<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;color:#000000">Thank you very much Chris!</div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:#000000">works like a charm. I already know a bit about generator, but I haven't thought that such is also possible. Impressively powerful language</div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:#000000"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:#000000">best,</div><div class="gmail_default" style="font-family:tahoma,sans-serif;color:#000000">Stephan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 3 October 2014 09:01, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, Oct 3, 2014 at 4:36 PM, Stephan Sahm <<a href="mailto:Stephan.Sahm@gmx.de">Stephan.Sahm@gmx.de</a>> wrote:<br>
> Thank you both very much,<br>
><br>
> I see that this longevity problem is really crucial. A pity for me ;)<br>
> best wishes,<br>
> Stephan<br>
<br>
</span>In the general case, it is. But if you want it just for your own<br>
generators, it ought to be possible to write a decorator that<br>
yields-from your original function, retains the return value, and then<br>
reraises the exception repeatedly. Here's a simple version:<br>
<br>
def gen():<br>
    yield 0<br>
    return 1<br>
class repeater:<br>
    def __init__(self):<br>
        self.g=gen()<br>
    def __iter__(self): return self<br>
    def __next__(self):<br>
        if hasattr(self, "done"): raise StopIteration(self.done)<br>
        try:<br>
            return next(self.g)<br>
        except StopIteration as exc:<br>
            self.done=exc.value<br>
            raise<br>
<br>
Generalizing this is left as an exercise for the reader.<br>
<br>
ChrisA<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br></div>