eof?

Rupert Scammell rupe at metro.yak.net
Wed Aug 15 21:24:13 CEST 2001


"Steven D. Majewski" <sdm7g at Virginia.EDU> wrote in message news:<mailman.997883532.20811.python-list at python.org>...
> On Wed, 15 Aug 2001, Alex Martelli wrote:
> 
> > "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?
> > 
> > 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).
> 
> And in 2.2, file objects can automatically return an iterator 
> in the context of a for loop, so you can just say:
> 
> 	for line in open( filename ):
> 		process(line)
> 
> -- Steve Majewski

Interesting...

I was aware of the readlines() limitation, but I'm wondering how
xreadlines() differs from using something like for line in
fileinput.input([file]): process(line), which I've been using instead
of readlines()?

Any appreciable performance or mem usage differences here?

Thanks,

--- Rupert

Rupert Scammell
rupe at metro.yak.net
http://metro.yak.net:8080



More information about the Python-list mailing list