How to count lines in a text file ?

Andrew Dalke adalke at
Wed Sep 22 15:48:21 EDT 2004

Bengt Richter wrote:
> or, if you _are_ willing to read in the whole file,
>     open('text.txt').read().count('\n')

Except the last line might not have a terminal newline.

				dalke at

More information about the Python-list mailing list