Python逐行读取文件内容(Python read file line by line)

Python逐行读取文件内容
thefile= open("foo.txt")
line = thefile.readline()
while line: print line,
  line = thefile.readline() thefile.close()


Windows下文件路径的写法:
E:/codes/tions.txt


写文件:
thefile= open("foo.txt", "rw+")
for item in thelist: thefile.write("%s\n"% item)
thefile.close()
 
posted @ 2015-04-18 19:45  emanlee  阅读(6080)  评论(0编辑  收藏  举报