dabase.com → Kai's Tech Tips → Python → Counting lines in a file Counting lines in a file Published: Wednesday, Dec 26, 2007 Last modified: Tuesday, Oct 7, 2025 This should do it: print 'Line count: %s' % len(open(file).readlines()) ←Previous Next→