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

Alex Martelli aleax@aleax.it
Wed, 17 Jul 2002 18:34:09 +0200


On Wednesday 17 July 2002 06:23 pm, Guido van Rossum wrote:
	...
> > But iterables, they ain't, just like rewindable iterators in general
> > aren't.
>
> Can you remind me of your definition of "iterable"?  Mine is
> "something for which iter() works", which clearly isn't yours. :-)

Right -- I mean something closer to what I've seen others call
"a container".  By your definition, iterators are indeed iterable.
I would love for all iterables-by-your-definition to divide neatly
into iterators and what-many-call-containers.

The file object, unless you make it into an iterator, is not "a
container" like all others and just sits there -- a bit of a wart.

> > f.seek does cooperate with f.next now, doesn't it?  since it
> > invalidates f's xreadlines object, if any?
>
> Not yet.  You may have seen Oren's patch for this.  Unfortunately it

Right -- that's what I had in mind.  I had also tweaked it so that
readline sort of interoperated with it (delegating to next if the file
object is holding an xreadlines object) and sent the modified patch
to Oren but he disliked it (because it meant readline would not
respect its numeric argument, if any, in that case).

> has a problem in that it creates a cycle, and neither type supports
> GC...
>
> So I'm not sure if it ever will -- this is an implementation mess as
> much as a conceptual mess. :-(

I see your point.  Darn!-(.


Alex