[Python-ideas] Change how Generator Expressions handle StopIteration

Terry Reedy tjreedy at udel.edu
Wed Nov 5 01:55:51 CET 2014


On 11/4/2014 6:12 PM, Yotam Vaknin wrote:
> Firstly, sorry for my buggy code that began all this mess.
>
> But what about adding a named parameter to the next function, specifying
> an exception to be raised on StopIteration, allowing it to propagate?

There is already a 'default' option, so the two would have to be 
mutually exclusive.

"next(iterator[, default])

     Retrieve the next item from the iterator by calling its __next__() 
method. If default is given, it is returned if the iterator is 
exhausted, otherwise StopIteration is raised."

I believe either adding an alternate exception, or raising the default 
if it is an exception, has been discussed before on this list.  In 
cannot remember details other than the obvious fact that nothing was 
changed.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list