how to count lines in a file ?
Andreas Kostyrka
andreas at kostyrka.priv.at
Sat Jul 27 04:08:36 EDT 2002
Am Die, 2002-07-23 um 18.35 schrieb Sean 'Shaleh' Perry:
>
> On 23-Jul-2002 Shagshag13 wrote:
> > do = 'wc ' + filename
> > p = os.popen(do, 'r')
> > line = p.read()
> > p.close()
> >
>
> read() copies the whole chunk into memory as well so you might as well use
> readlines(). otherwise just use a standard loop and counter.
Well, no matter how large the file is, wc just produces one line.
So read() is ok :)
Andreas
More information about the Python-list
mailing list