文件按行读取,大多数可能如下:
file = open("a.txt")
while 1:
line = file.readline()
if not line:
break
file.close()
但使用文件迭代更加简约
file = open("sample.txt")
for line in file:
pass
file.close()
文件按行读取,大多数可能如下:
file = open("a.txt")
while 1:
line = file.readline()
if not line:
break
file.close()
但使用文件迭代更加简约
file = open("sample.txt")
for line in file:
pass
file.close()
本文标题:文件按行读取小技巧
本文链接:https://www.haomeiwen.com/subject/hyjwuftx.html
网友评论