A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-July/026282.html below:

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

[Python-Dev] Single- vs. Multi-pass iterabilityAlex Martelli aleax@aleax.it
Thu, 11 Jul 2002 13:09:14 +0200
On Thursday 11 July 2002 12:47 pm, Guido van Rossum wrote:
> > > Proposal: make files really support the iterator
> > > protocol. __iter__ would return self and next() would call
> > > readline and raise StopIteration if ''.  If anyone wants the
> > > xreadline performance improvement it should be explicit.
>
> No.  I won't have "for line in file" be slower than attainable.

+1.  I _intensely_ want to be able to teach beginners to use "for line in 
file" and have it be fast in the common case.  "Nice" behavior for rarer 
cases of prematurely interrupted loops is OK, if feasible, but secondary.  
Having "for line in file" play nicely with other method calls on 'file' has 
no importance to me in this context -- no more than, e.g., having "for item 
in alist" play nicely with calls to mutating methods of object alist.


> The only solution I accept is a complete rewrite of the I/O system
> without using stdio, so xreadlines can be integrated.

I thought Just's suggestion (about having the file object remember
the xreadlines object in use, so that another for loop would continue
right where the first one exited) seemed like a reasonable hack -- a
compromise of reasonably little effort for some small secondary gain.

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?


Alex




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4