python一行一行读取文件的方法

[python] 2024-04-28 圈点792

摘要:python一行一行读取文件的方法

1,一行一行的读取文件:

with open("xoxxoo.txt") as file:  

for line in file:

    print line


2,

f = open("xoxxoo.txt","r")  

lines = f.readlines()#读取全部内容  

for line in lines  

    print line  


3

f = open("foo.txt")             # 返回一个文件对象  

while 1:  

  line = f.readline()             # 调用文件的 readline()方法

  print line                 # 后面跟 ',' 将忽略换行符  

f.close()  

python  读取文件  

感谢反馈,已提交成功,审核后即会显示