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'?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; "subject:' ": 0.07; 'ex:': 0.09; 'pep': 0.09; 'try:': 0.09; 'val': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'propagated': 0.16; 'subject:yield': 0.16; 'xs:': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'subject:] ': 0.20; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'specifies': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'subject:from': 0.34; 'except': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'yield': 0.36; 'pm,': 0.38; 'even': 0.60; 'more': 0.64; 'different': 0.65; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=oNZSJBBgnFi1PYDLyKomat1Z4vszTyhwK384AQffuYk=; b=A/jm6aT4yXPM1oE/CE2Z4yri50YRLUyAfqB7p+CTwIxCoA3S82+UjTj3Aaw8Tuo5qE M/LFGu9zBm9j+sXsB+5BMTwB8GAy1+RYoNU25TGqeTbAkOuDLuUKyRESKqQXXBAexn5d z5bSMExNoj4oN/DgwZ1LQjuIjtIF39n0VQMRJi1WkPbNCdM1rYSB4W0xLZbPk8zNWdr2 nf4Bc3DzTIOHvvq6SAP7C2vxuDnFZ3fQBhwfcyky7f3Oi6elqCcMr7nq/seu/BYq1iCK ij+deF3fykt5TzMIMR5BdujeRiF7ReozZYv9E+y/fkP3y3WWOoaMbVvsnWLSmNK9ZDOL 27Dg==
MIME-Version 1.0
X-Received by 10.51.17.2 with SMTP id ga2mr15802529igd.2.1408010566254; Thu, 14 Aug 2014 03:02:46 -0700 (PDT)
In-Reply-To <CAFTm5RuPvUaMarWLeATmi7RG5n+rhcw+JE_11fx3dPMp=bN8bA@mail.gmail.com>
References <CAFTm5Ru8nfNt2UtyeBiEh-7Cf5RQZShYV9ha=6HACifCcVUG4w@mail.gmail.com> <CAPTjJmo-0aqxeosa1bM=jtuAdwoZLiiG20kDp7RGvP3Zx65_9w@mail.gmail.com> <CAFTm5RuPvUaMarWLeATmi7RG5n+rhcw+JE_11fx3dPMp=bN8bA@mail.gmail.com>
Date Thu, 14 Aug 2014 20:02:46 +1000
Subject Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12991.1408010569.18130.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408010569 news.xs4all.nl 2849 [2001:888:2000:d::a6]:49967
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76291

Show key headers only | 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