# You can do it by iterating through a simple for loop fhand = open('path and the file name') count = 0 for line in fhand: count += 1 print('The number of lines in the file is:', count)