# coding:utf-8
file1 = open('data.txt', 'r', encoding='utf-8') # 打开要去掉空行的文件
file2 = open('data2.txt', 'w', encoding='utf-8') # 生成没有空行的文件
for line in file1.readlines():
if line == '\n':
line = line.strip('\n')
file2.write(line)
file1.close()
file2.close()
python读取txt文件并删除文中空行
猜你喜欢
转载自blog.csdn.net/qq_36756866/article/details/123073264
今日推荐
周排行