[Python-Dev] Re: A `cogen' module [was: Re: PEP 218 (sets); moving set.py to Lib]

Oren Tirosh oren-py-d@hishome.net
Wed, 28 Aug 2002 16:11:39 -0400


On Wed, Aug 28, 2002 at 03:41:00PM -0400, Guido van Rossum wrote:
> > > Or you might use Oren's favorite rule of thumb and listify it when iter(x)
> > > is iter(x) (or iter(x) is x).
> > 
> > I'm a bit annoyed by the idea that `iter(x)' might require some computation
> > for producing an iterator, and that we immediately throw away the result.
> > Granted that `__iter__(self): return self' is efficient when an object is
> > an iterator, but nowhere it is said that `__iter__' has to be efficient
> > when the object is a container, and it does not shock me that some complex
> > containers require time to produce their iterator.  I much prefer limiting
> > the use of `__iter__' for when one intends to use the iterator...
> 
> Yes, that's why I prefer to just make a list() copy.

Oh, come on you two... stop beating up the poor strawman. The reiter()
function doesn't make a single redundant call to __iter__.  It's just 
like iter() but ensures in passing that the result is really a fresh 
iterator.

	Oren