标签:style blog color os sp for 文件 div on
Python读取txt文件,有两种方式:
(1)逐行读取
1 data=open("data.txt") 2 line=data.readline() 3 while line: 4 print line 5 line=data.readline()
(2)一次全部读入内存
1 data=open("data.txt") 2 for line in data.readlines(): 3 print line
标签:style blog color os sp for 文件 div on
原文地址:http://www.cnblogs.com/acode/p/4104536.html