Determining the Number of Lines in a File : readlines « File « Python Tutorial






filePath = "input.txt"

lineCount = len(open(filePath, 'rU').readlines())
print "File %s has %d lines." % (filePath,lineCount)








12.12.readlines
12.12.1.Read all lines
12.12.2.Read lines into a buffer
12.12.3.Determining the Number of Lines in a File