[Q] is 'yield from' syntax sugar for 'for'+'yield'?
Makoto Kuwata
kwa at kuwata-lab.com
Thu Aug 14 08:57:43 EDT 2014
On Thu, Aug 14, 2014 at 7:02 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Aug 14, 2014 at 7:59 PM, Makoto Kuwata <kwatch at gmail.com> wrote:
> > I understand that 'val = yield from xs' is completely different from::
> >
> > for x in xs:
> > ret = yield x
> > val = x
> >
> > Return value is propagated by StopIteration, like:
> >
> > it = iter(xs)
> > try:
> > while 1:
> > yield next(it)
> > except StopIteration as ex:
> > val = ex.value
>
> It's even more complicated than that. The PEP specifies the exact
> semantics.
>
> ChrisA
>
Well, I wrote the above code in order to describe `value is propagated by
StopIteration'
because I misunderstood that it is propagated by return value of yield
statement
(see my first post).
I have known that `yield from` is very complicated (thanks to your reply).
--
regards,
kwatch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140814/656f476e/attachment.html>
More information about the Python-list
mailing list