第一种:
with open('D:/doctor/数据预测/Data/样本数据.txt', 'r') as f:
lines = f.readlines()
for line in lines:
print(line)
第二种:
for line in open('D:/doctor/数据预测/Data/样本数据.txt', 'r'):
print(line)
第三种:
f = open('D:/doctor/数据预测/Data/样本数据.txt', 'r')
line = f.readline()
while line:
print(line,) #line后面的‘,’将忽略换行符
line = f.readline()
f.close() #注意这里需要对打开文件关闭