Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76291

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?

References <CAFTm5Ru8nfNt2UtyeBiEh-7Cf5RQZShYV9ha=6HACifCcVUG4w@mail.gmail.com> <CAPTjJmo-0aqxeosa1bM=jtuAdwoZLiiG20kDp7RGvP3Zx65_9w@mail.gmail.com> <CAFTm5RuPvUaMarWLeATmi7RG5n+rhcw+JE_11fx3dPMp=bN8bA@mail.gmail.com>
Date 2014-08-14 20:02 +1000
Subject Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.12991.1408010569.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Aug 14, 2014 at 7:59 PM, Makoto Kuwata <kwatch@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'? Chris Angelico <rosuav@gmail.com> - 2014-08-14 20:02 +1000

csiph-web