文件按行读取,大多数可能如下:
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()