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