python 中如何删除空行
001、
(base) root@PC1:/home/test3# ls a.txt test.py (base) root@PC1:/home/test3# cat a.txt ## 测试数据 ddd ff ff jkj jj dffffffgg dgfggggg (base) root@PC1:/home/test3# cat test.py ## 测试脚本 #!/usr/bin/python in_file = open("a.txt", "r") out_file = open("result.txt", "w") for i in in_file: if i.isspace(): continue else: out_file.write(i) in_file.close() out_file.close() (base) root@PC1:/home/test3# python test.py ## 运行程序 (base) root@PC1:/home/test3# ls a.txt result.txt test.py (base) root@PC1:/home/test3# cat result.txt ## 程序结果 ddd ff ff jkj jj dffffffgg dgfggggg