Python读取txt文件,有两种方式:
(1)逐行读取
data=open("data.txt")
line=data.readline()
while line:
print line
line=data.readline()
(2)一次全部读入内存
data=open("data.txt")
for line in data.readlines():
print line
Python读取txt文件,有两种方式:
(1)逐行读取
data=open("data.txt")
line=data.readline()
while line:
print line
line=data.readline()
(2)一次全部读入内存
data=open("data.txt")
for line in data.readlines():
print line