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

Guido van Rossum guido@python.org
Wed, 17 Jul 2002 12:23:46 -0400


> All files have seek and write, but not on all files do they work -- and
> the same goes for iteration.  I.e., it IS something of a mess, probably
> because the file object's is the only example of "fat interface" problem
> in Python -- an interface that exposes a lot of methods, with many
> objects claiming they implement that interface but actually lying
> (because they only implement a subset of it -- trying to use methods
> they can't in fact provide raises exceptions).

Yup.  I inherited this from C stdio. :-(

> 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. :-)

> 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
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. :-(

--Guido van Rossum (home page: http://www.python.org/~guido/)