1.read
- 读取全部文件
with open("test.text", "r",encoding='utf8') as f:
print(f.read())
输出:
2.readline
- 读取下一行
with open("test.text", "r",encoding='utf8') as f:
# print(f.read())
for i in range(10):
print(f.readline())
输出:
3.readlines
- 读取全部,并返回一个列表
with open("test.text", "r",encoding='utf8') as f:
print(f.readlines(), type(f.readlines()))
输出:
原文地址:https://www.cnblogs.com/bigox/p/11619297.html
时间: 2024-11-01 14:57:30