[Python-Dev] Re: anonymous blocks

Tim Delaney tcdelaney at optusnet.com.au
Mon Apr 25 02:37:44 CEST 2005


Guido van Rossum wrote:

> but for backwards compatibility with the existing argument-less next()
> API I'm introducing a new iterator API next_ex() which takes an
> exception argument.  If that argument is None, it should behave just
> like next().  Otherwise, if the iterator is a generator, this will

Might this be a good time to introduce __next__ (having the same signature 
and semantics as your proposed next_ex) and builtin next(obj, 
exception=None)?

def next(obj, exception=None):

    if hasattr(obj, '__next__'):
        return obj.__next__(exception)

    if exception is not None:
        return obj.next(exception) # Will raise an appropriate exception

    return obj.next()

Tim Delaney 



More information about the Python-Dev mailing list