How to count lines in a text file ?

Andrew Dalke adalke at mindspring.com
Wed Sep 22 18:45:52 EDT 2004


Alex Martelli wrote:
> ....and wc would then not count that non-line as a line, so why should
> we...?  Witness...:


   'Cause that's what Python does.  Witness:

% echo -n 'bu' | python -c \
?       'import sys; print len(sys.stdin.readlines())'
1

   ;)

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list