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('输出成功....')
功能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)