python 中统计文件的行数

 

001、

[root@pc1 test]# ls
a.txt  test.py
[root@pc1 test]# cat a.txt
1
2
3
4
5
[root@pc1 test]# cat test.py
#!/usr/bin/python
in_file = open("a.txt", "r")
lines = in_file.readlines()
print(len(lines))
[root@pc1 test]# python test.py
5

 

posted @ 2022-10-29 00:40  小鲨鱼2018  阅读(67)  评论(0)    收藏  举报