Mega Code Archive

 
Categories / Python Tutorial / File
 

Determining the Number of Lines in a File

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