python去掉空白行
程序员文章站
2022-06-04 19:30:00
...
# -*- coding: utf-8 -*-
'''
python读取文件,将文件中的空白行去掉
'''
def delblankline(infile, outfile):
infopen = open(infile, 'r',encoding="utf-8")
outfopen = open(outfile, 'w',encoding="utf-8")
lines = infopen.readlines()
for line in lines:
if line.split():
outfopen.writelines(line)
else:
outfopen.writelines("")
infopen.close()
outfopen.close()
delblankline("源文件路径", "目标文件路径")
上一篇: JDK1.8 Stream
下一篇: linux命令cat过滤注释行和空白行