python 中如何删除行首的空格或者tab
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 k fff iyyee (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: i = i.strip() out_file.write(i + "\n") 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 k fff iyyee