读取存在空行的文件,删除其中的空行,并将其保存到新的文件中;
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/18 21:41
# @Author : cunyu
# @Site : cunyu1943.github.io
# @File : deleteBlankLines.py
# @Software: PyCharm
"""
读取存在空行的文件,删除其中的空行,并将其保存到新的文件中
"""
with open('old.txt','r',encoding = 'utf-8') as fr,open('new.txt','w',encoding = 'utf-8') as fd:
for text in fr.readlines():
if text.split():
fd.write(text)
print('输出成功....')