python中 输出文本空行行号
python中 输出空行行号
[root@PC1 test]# ls a.txt test.py [root@PC1 test]# cat -n a.txt 1 01 02 03 04 2 05 06 07 08 3 4 09 10 11 12 5 6 7 13 14 15 16 8 17 18 19 20 [root@PC1 test]# cat test.py #!/usr/bin/env python # -*- coding:utf-8 -*- input_file = "a.txt" with open(input_file, "r") as input: for i,j in enumerate(input): j = j.strip() if j: continue else: print(i + 1) [root@PC1 test]# python test.py 3 5 6
。