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

Barry Warsaw barry at python.org
Mon Mar 5 19:44:12 CET 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mar 5, 2007, at 1:36 PM, Martin v. Löwis wrote:

> -1. I dislike the introduction of more builtins unless they have a  
> true
> generality (i.e. are likely to be needed in many programs). For this
> one, I think the normal usage of __next__ will be with a for loop, so
> I don't think one would often need an explicit next() invocation.

I have had occasional need to call .next() explicitly.  IIRC the code  
in question was handed an iterator but only needed the first object  
out of the iterator.  It would be really ugly to have to use __next__ 
() or force a once-through for loop.

OTOH, making iterators callable as equivalent to .next() as I think  
Raymond suggested sounds about perfect.  You get __next__(), plus  
explicit iteration with no additional built in necessary.

- -Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRexk/XEjvBPtnXfVAQIq0gP+KULlyQNTAEsrxqQIQYO8e5eP/zbIazsa
idKofJaQVEp9QbpIUBWj4RdzfesEkhjhy3dtNo3APGMCej4YsPhuHQMeoucVSKA/
1FUXwyVUliqa4yrN9pFadXYTd9dZcep++Hbgb76REp2wUejdNkO0k/lnIZ0JERcv
33Wt64r21x4=
=ZWgi
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list