[Python-3000] PEP: rename it.next() to it.__next__(), add a next() built-in

Neil Schemenauer nas at arctrix.com
Tue Mar 6 02:29:31 CET 2007


Ka-Ping Yee <python-dev at zesty.ca> wrote:
> This is exactly why the iterator protocol method should be named
> __next__: so it can't collide with method names used for other
> purposes.

And yet people are suggesting that __call__ be used instead of
__next__.  If people believe iterators should be separate objects
then there is no problem with name collisions.  Even if you don't
believe in always using separate iterator objects, using one is not
such a big burden in the case of name collisions.

The argument that all "protocol" methods should have double
underscore names seems to be pretty weak too.  It's only an appeal
for consistency, I think.  We don't suggest that file-like objects
should implement __read__() instead of read(), for example.

  Neil



More information about the Python-3000 mailing list