首页 > 代码库 > Python:如何删除文件中的空白行?

Python:如何删除文件中的空白行?

def delblankline(infile,outfile):    infopen = open(infile,r)    outfopen = open(outfile,w)    lines = infopen.readlines()    for line in lines:        if line.split():            outfopen.writelines(line)        else:            outfopen.writelines("")    infopen.close()    outfopen.close()    delblankline("output.py","output1.py")

 

Python:如何删除文件中的空白行?