[Python-Dev] iterator API in Py3.0

Aahz aahz at pythoncraft.com
Fri Mar 3 20:15:12 CET 2006

On Wed, Mar 01, 2006, Raymond Hettinger wrote:
> I usually let this sort of thing slide, but the iterator API is too
> important for trivial, incompatible, and damaging changes.  Looking
> back at Guido's original rationale for naming the method next()
> instead of __next__(), http://www.python.org/peps/pep-0234.html , it
> does not look like any of those reasons will cease to apply in Py3.0.

OTOH, there is a final comment that choosing next() was perhaps a
mistake that cannot be rectified.  However, it can certainly be fixed in
Python 3.0.

My argument in favor of switching to __next__() is rather simple:

* As a writer/teacher, I want to be able to say, "All Python special
methods have leading and trailing double-underscore."  Period, end of

* As a programmer, I want special methods to be VISIBLE.  Python is a
language for reading code.

* Finally, as a debater in the future of the Python language, I don't
want any time taken up discussing whether any future special method
should get the same kind of special treatment we've given to next().

As for your point about efficiency, I don't much care whether we get a
built-in next() function, but I think that anyone who is concerned about
efficiency should do

    next = obj.__next__

which saves an attribute lookup, too.  I still think the vast majority of
cases will stick with for loops that automatically call __next__()
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis

More information about the Python-Dev mailing list