eof?

Alex Martelli aleaxit at yahoo.com
Wed Aug 15 09:01:45 EDT 2001


"Dietmar Lang" <dietmar at wohnheim.fh-wedel.de> wrote in message
news:3B7A4C7C.CF1A3C3A at wohnheim.fh-wedel.de...
>
> Hi,
>
> > There are several ways.  Best overall, today (Python 2.1):
> >
> >     for line in fh.xreadlines():
> >         process(line)
>
> Is xreadlines something I missed or is it a misspelled readlines?
> Because as far as I know readlines reads in the whole file into a list
> containing the lines, which might not be so practical if the file is
> waay big?

You missed the introduction of xreadlines, which satisfies
exactly this objection.  xreadlines is to readlines like xrange
is to range: it produces its sequence a little at a time (you
can control the buffersize used if you want) rather than
making it all in memory at one time, and therefore it may
be more general if you may need to process sequences that
are very large (readlines is probably going to be faster if the
file isn't that large compared to available memory, though).


Alex






More information about the Python-list mailing list