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

Paul Svensson paul-python@svensson.org
Fri, 19 Jul 2002 13:21:26 -0400 (EDT)


On Fri, 19 Jul 2002, Aahz wrote:

>And how does that integer index change?  The for loop in Python <2.2 has
>an internal state object.  Iterators are the external manifestation of
>that state object, generalized to objects other than sequences.  I'm
>surprised that anyone is surprised that the state object gets
>mutated/destroyed.  I'm also surprised that people are surprised about
>what happens when that state object is coupled to an inherently mutating
>object such as file objects.

All the surprises I see stem from confusion between what is the object
being iterated over, and what is the object holding the state of the
iteration.  Iterators returning self for __iter__() is the major cause
of this confusion.  I agree that in the general case, the boundary may
not always be clear, but Ping's proposal cleans up what's seen 99.9%
of the time.

Pending the pain of the yet unseen migration plan, I'm
+1 on removing __iter__ from all core iterators
+1 on renaming next() to __next__()
+1 on presenting file objects as iterators rather than iterables
+0 on the new 'for x from y' syntax

	/Paul