[Python-ideas] Propagating StopIteration value [PS. #2]

Jan Kaliszewski zuo at chopin.edu.pl
Thu Oct 11 01:38:21 CEST 2012

W dniu 11.10.2012 01:29, Jan Kaliszewski napisał(a):
>> The goal described by the OP could be reached with a wrapper
>> generator -- something like this:
> [snip]
> PS. A more convenient version (you don't need to repeat yourself):

PS2. Sorry for flooding, obviously it can be simpler:

     import collections

     def genfrom(iter_factory, *args):
         final_value = None
         def catching(iterable):
             nonlocal final_value
             final_value = yield from iterable
         args = [catching(arg.iterable) if isinstance(arg, genfrom.this) 
else arg
                 for arg in args]
         yield from iter_factory(*args)
         return final_value

     genfrom.this = collections.namedtuple('propagate_from_this', 


More information about the Python-ideas mailing list