读写 去除空格

# coding = utf-8
def clearBlankLine(path):
    file1 = open(path, 'r', encoding='utf-8') # 要去掉空行的文件
    yuan_list=file1.readlines()
    file1.close()
    file2 = open(path, 'w', encoding='utf-8') # 生成没有空行的文件
    try:
        for line in yuan_list:
            if line == '\n':
                line = line.strip("\n")
            file2.write(line)
    finally:
        file2.close()


if __name__ == '__main__':
    clearBlankLine()

 

上一篇:Shell脚本变量判断参数命令


下一篇:linux基础命令:cp