[Python-Dev] Single- vs. Multi-pass iterability

Oren Tirosh oren-py-d@hishome.net
Fri, 12 Jul 2002 00:59:28 +0300


On Thu, Jul 11, 2002 at 08:19:31AM -0400, Guido van Rossum wrote:
> > Guess I must be missing something?  Of course the "complete rewrite"
> > is an alluring prospect -- for many other reasons, such as enabling
> > user control of file buffering in cross-platform ways, *yum* -- but it's not 
> > going to happen in time for 2.3 anyway, is it?
> 
> I'm not going to hold up the 2.3 release, but if a patch lands in the
> SF patch manager, I'm not going to reject it.  Hint, hint. :-)

http://www.python.org/sf/580331

No, it's not a complete rewrite of file buffering.  This patch implements 
Just's idea of xreadlines caching in the file object.  It also makes a file 
into an iterator: __iter__ returns self and next calls the next method of
the cached xreadlines object.

See my previous postings for why I think a file should be an iterator.

With this patch any combination of multiple xreadlines and iterator protocol 
operations on a file object is safe. Using xreadlines/iterator followed by 
regular readline has the same buffering problem as before. 

	Oren