how to count lines in a file ?

Denis S. Otkidach ods at fep.ru
Tue Jul 23 12:53:42 EDT 2002


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

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]
http://diveinto.python.ru/ [ru]






More information about the Python-list mailing list