Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:: [': 0.04; 'syntax': 0.04; "subject:' ": 0.07; 'ex:': 0.09; 'pep': 0.09; 'try:': 0.09; 'val': 0.09; '7:35': 0.16; 'propagated': 0.16; 'subject:yield': 0.16; 'url:peps': 0.16; 'xs:': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'subject:] ': 0.20; 'thanks.': 0.20; 'seems': 0.21; 'aug': 0.22; 'email addr:gmail.com>': 0.22; 'to:name :python-list@python.org': 0.22; 'of.': 0.24; 'url:dev': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:python': 0.33; 'cases': 0.33; 'subject:from': 0.34; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; 'edge': 0.36; 'yield': 0.36; 'url:org': 0.36; 'too': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'simply': 0.61; 'simple': 0.61; 'you.': 0.62; 'more': 0.64; 'different': 0.65 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:to :content-type; bh=Q8fjUIRTWZqP5fSrL2qBmN1oZx836G4xJVcExntQ8rE=; b=uotN9KS5LMhPTXRLO0iGTFDD9v+rfWwxwOCFJcKvGO1giVmdyc85Mo8wJycxOT2XOu 5q0prNeAe3cq3vGGejpTGwf8t8f2J2y6v44y9hkaJRSbY1FQbteZvXpv51qZbZr+bq9H dypxGx70+inq2JC1An9dVCJAOX68/BtYMSBys76X3qMHZY1+vFp3YAaPGwkWobxKXzOE 5EIr44VkHITTqUSUmmyThrt/93suepjKZE5KLlnOSii51HvJNMHZlqO0Oxd92sTl+geM R1BFfzaN0VSTkCQ1UhwbdRKP+L0rDLxrV3Dyz3QDrk64kTZxhlpDmI4163IOF60mZHjF f6Qw== MIME-Version: 1.0 X-Received: by 10.50.57.68 with SMTP id g4mr57332499igq.48.1408010365981; Thu, 14 Aug 2014 02:59:25 -0700 (PDT) In-Reply-To: References: Date: Thu, 14 Aug 2014 18:59:25 +0900 Subject: Re: [Q] is 'yield from' syntax sugar for 'for'+'yield'? From: Makoto Kuwata To: "python-list@python.org" Content-Type: multipart/alternative; boundary=047d7bdc0d9eb45e82050093f5c7 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408010368 news.xs4all.nl 2967 [2001:888:2000:d::a6]:43653 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76290 --047d7bdc0d9eb45e82050093f5c7 Content-Type: text/plain; charset=UTF-8 On Thu, Aug 14, 2014 at 6:38 PM, Chris Angelico wrote: > On Thu, Aug 14, 2014 at 7:35 PM, Makoto Kuwata wrote: > > I understand that:: > > > > yield from xs > > > > is syntax suger of:: > > > > for x in xs: > > yield x > > Not just. It's like that for simple cases, but there are edge cases > that are much more complicated to do manually, and are simply taken > care of. Best would be to read the PEP itself: > > http://www.python.org/dev/peps/pep-0380/ > > ChrisA > Thank you. It seems too complicated... 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 Thanks. -- regards, kwatch --047d7bdc0d9eb45e82050093f5c7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Thu, Aug 14, 2014 at 6:38 PM, Chris Angelico &= lt;rosuav@gmail.com> wrote:
On Thu, Aug 14, 2014 at 7:35= PM, Makoto Kuwata <kwatch@gmail.com= > wrote:
> I understand that::
>
> =C2=A0 =C2=A0 yield from xs
>
> is syntax suger of::
>
> =C2=A0 =C2=A0 for x in xs:
> =C2=A0 =C2=A0 =C2=A0 yield x

Not just. It's like that for simple cases, but there are edge cas= es
that are much more complicated to do manually, and are simply taken
care of. Best would be to read the PEP itself:

http= ://www.python.org/dev/peps/pep-0380/

ChrisA

Thank you. It seems too complica= ted...
I understand that 'val =3D yield from xs' is compl= etely different from::

=C2=A0 =C2=A0for x in xs:
=C2=A0 =C2=A0 =C2=A0 ret =3D yield x
=C2=A0 =C2=A0val =3D x
=

Return value is propagated by StopIteration, like:
<= /div>

=C2=A0 =C2=A0it =3D iter(xs)
=C2=A0=C2= =A0 try:
=C2=A0 =C2=A0 =C2=A0while 1:
=C2=A0 =C2=A0= =C2=A0 =C2=A0yield next(it)
=C2=A0 =C2=A0except StopIteration as ex:
=C2=A0 =C2=A0 =C2= =A0val =3D ex.value


Thanks.

--
regards,
kwatch
<= /div> --047d7bdc0d9eb45e82050093f5c7--