用with来打开文本文件 with open ('text.txt') as f: for line in f.readlines(): print(line) 这种方法的好处就是如果出了异常也会自动提示报错。