python readline逐行读,怎么判断已到末尾

2025-01-02 15:07:56
推荐回答(1个)
回答1:

代码如下:
filename = raw_input('Enter your file name') #输入要遍历读取的文件路径及文件名
file = open(filename,'r')
done = 0
while not done:
aLine = file.readline()
if(aLine != ''):
print aLine,
else:
done = 1
file.close() #关闭文件