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()
