使用python逐行读取文件内容的几个方法?
方法一:使用readline读取:
f = open("fix.txt")
line = f.readline()
while line:
print line
line = f.readline()
f.close()
方法二:
for line in open("fix.txt"):
print line
方法三:
f = open("c:\\fix.txt","r")
lines = f.readlines()
for line in lines
print(line)
方法四:
with open(filename) as file_obect:
lines = file_object.readlines
for line in lines:
print(line)
建议使用方法四~