去除d0.txt中空行并保存在d1.txt 如果要删除带有空格的空行,可以考虑把判断条件换成正则
with open('d0.txt','r',encoding='utf-8') as f,open('d1.txt','w',encoding='utf-8') as f1: for i in f.readlines(): if i != '\n': f1.write(i)