在跑程序使用print()写入文件的时候,多写入了\n,不想再重新跑了,于是直接把空行给去除掉吧。
如图:
with open('C:\\Users\\Hou bin\\Desktop\\errors_137.txt','r',encoding = 'utf-8') as fr,open('C:\\Users\\Hou bin\\Desktop\\errors_bird216_137.txt','w',encoding = 'utf-8') as fd:
for text in fr.readlines():
if text.split():
fd.write(text)
print('输出成功....')
结果: