📌  相关文章
📜  python 从文件中删除空行 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:29.658000             🧑  作者: Mango

代码示例3
with open(fname, 'r+') as fd:
    lines = fd.readlines()
    fd.seek(0)
    fd.writelines(line for line in lines if line.strip())
    fd.truncate()