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

Guido van Rossum guido at python.org
Tue Mar 6 19:24:50 CET 2007


Having now read this entire thread I am going to accept Ping's PEP.
Adding the sentinel argument to the next() builtin was what did it for
me: it neatly solves the problem if having to catch that StopIteration
in 99% of the cases.

Thanks all for the discussion!

--Guido

On 3/6/07, Guido van Rossum <guido at python.org> wrote:
> On 3/5/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> > Ka-Ping Yee wrote:
> >
> > >     Just like getattr, two-argument next(iter, sentinel)
> > >     returns sentinel if StopException is caught.
> >
> > +1. I've written a number of pieces of code where this
> > would have made things neater. Just about any place
> > where I've used .next() explicitly, in fact -- it
> > always seems awkward having to deal with StopIteration.
>
> Ditto.
>
> Also notice the (in some sense ironic) complementary symmetry with
> iter(function, sentinel).
>
> --
> --Guido van Rossum (home page: http://www.python.org/~guido/)
>


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


More information about the Python-3000 mailing list