Python can count the number of lines in a file. do you believe this? Believe it or not, or I believe it. Next let's take a look at how python counts the number of lines in a file. the code is simple. python can count the number of lines in a file. do you believe this? Believe it or not, or I believe it. Next, let's take a look at how python counts the number of lines in a file. the code is very simple. I also made a comment and implemented it very easily...
1
2
3
4
5
6
7
8
9
# _ * _ Coding: utf_8 # import sys and the System OS module import sys import OS ''' to calculate the number of lines in a file ''' def countFileLines (filename ): count = 0 try: handle = open (filename, 'r') # loop file handle for eachline in handle: # accumulate count + = 1 # capture exceptions t IOError, e: print 'file open error', e return count print countFileLines ('/home/pythontab/tmp/. php ')