功能 python读取存在空行的文件,删除其中的空行,并将其保存到新的文件中; 代码 with open('input.txt','r',encoding = 'utf-8') as fr,open('output.txt','w',encoding = 'utf-8') as fd: for text in fr.readlines(): if text.split(): fd.write(text) print('输出成功....') input.txt放在文件名.py同目录当中。