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

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Mar 6 00:24:58 CET 2007


Terry Reedy wrote:

> One of the virtues, and as I recall, design purposes, of .next calls is to 
> be fast.  After the first call, execution jumps directly into the 
> pre-existing stack frame.

You're thinking of generators, but not all iterators
are implemented by generators. The built-in ones are
implemented in C.

Invoking a builtin .next() method via a protocol
function shouldn't be any slower than it is now.
In both cases you've got one name lookup and one
Python call, after which you go through the type
slot directly to a C function.

> It is then fairly 
> standard to factor out the attribute lookup with with 'xnext = x.next'

You could still do xnext = x.__next__ if you wanted.

--
Greg


More information about the Python-3000 mailing list