how to count lines in a file ?
Just
just at xs4all.nl
Tue Jul 23 13:58:54 EDT 2002
In article <mailman.1027443271.32201.python-list at python.org>,
"Denis S. Otkidach" <ods at fep.ru> wrote:
> On Tue, 23 Jul 2002, Shagshag13 wrote:
>
> S> hello,
> S>
> S> i need to count lines in a file (that i *can't* keep in
> S> memory, so can't use readlines())
>
> fp = open(filename)
> it = iter(fp)
> try:
> while it.next():
> count += 1
> except StopIteration:
> pass
How is that better than
count = 0
for line in open(filename):
count += 1
?
Just
More information about the Python-list
mailing list