时间:2021-07-01 10:21:17 帮助过:19人阅读
1
2
3
4
5
6
7
8
9
#_*_coding:utf_8 #引入sys和系统os模块 import sys import os ''' 计算某一个文件的行数 ''' def countFileLines(filename): count = 0 try: handle = open(filename, 'r') #循环文件句柄 for eachline in handle: #累加 count += 1 #异常捕获 except IOError, e: print 'file open error', e return count print countFileLines('/home/pythontab/tmp/a.php')