[Python-Dev] Re: anonymous blocks

Tim Delaney tcdelaney at optusnet.com.au
Tue Apr 26 00:10:44 CEST 2005

Paul Moore wrote:

> Hmm, it took me a while to get this, but what you're ssaying is that
> if you modify Guido's "what I really want" solution to use
>    VAR = next(it, exc)
> then this builtin next makes "API v2" stuff using __next__ work while
> remaining backward compatible with old-style "API v1" stuff using
> 0-arg next() (as long as old-style stuff isn't used in a context where
> an exception gets passed back in).

Yes, but it could also be used (almost) anywhere an explicit obj.next() is 

it = iter(seq)

while True:
    print next(it)

for loops would also change to use builtin next() rather than calling 
it.next() directly.

> I'd suggest that the new builtin have a "magic" name (__next__ being
> the obvious one :-)) to make it clear that it's an internal
> implementation detail.

There aren't many builtins that have magic names, and I don't think this 
should be one of them - it has obvious uses other than as an implementation 

> PS The first person to replace builtin __next__ in order to implement
> a "next hook" of some sort, gets shot :-)

Damn! There goes the use case ;)

Tim Delaney 

More information about the Python-Dev mailing list