How to count lines in a text file ?

Andrew Dalke adalke at mindspring.com
Wed Sep 22 21:48:21 CEST 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.

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list