Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!novso.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'true,': 0.05; 'subject:code': 0.07; '-0500': 0.09; 'exception,': 0.09; 'executed': 0.09; 'lawrence': 0.09; 'means,': 0.09; 'operand': 0.09; 'try:': 0.09; 'python': 0.11; 'language,': 0.12; 'language.': 0.14; '"or"': 0.16; '>>': 0.16; 'a()': 0.16; 'awkward,': 0.16; 'b()': 0.16; 'cleaner': 0.16; 'cui': 0.16; 'exiting': 0.16; 'guys,': 0.16; 'informing': 0.16; 'pythonic': 0.16; 'raised.': 0.16; 'really?': 0.16; 'roy': 0.16; 'rules.': 0.16; 'subclass': 0.16; 'subject:python': 0.16; 'exception': 0.16; 'followed': 0.16; 'all.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'hey': 0.18; '+0000': 0.22; 'to:name:python- list@python.org': 0.22; 'library,': 0.24; 'sorry,': 0.24; '>': 0.26; '(see': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; "doesn't": 0.30; 'dec': 0.30; 'skip:& 60': 0.30; 'especially': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'page.': 0.31; 'bunch': 0.31; 'continues': 0.31; 'culture.': 0.31; 'exceptions': 0.31; 'invoke': 0.31; 'probably': 0.32; 'url:python': 0.33; 'date:': 0.34; 'problem': 0.35; 'common': 0.35; 'except': 0.35; 'something': 0.35; 'requirement': 0.35; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'otherwise.': 0.36; 'url:listinfo': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'email addr:python.org': 0.37; 'convention': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'received:65.54': 0.38; 'received:65.54.190': 0.38; 'received:bay0.hotmail.com': 0.38; 'subject:': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'most': 0.60; 'first': 0.61; 're:': 0.63; 'our': 0.64; 'more': 0.64; 'different': 0.65; 'email name :python-list': 0.65; 'here': 0.66; 'frank': 0.68; 'smith': 0.68; 'integrated': 0.69; 'evaluate': 0.72; 'article': 0.77; 'do:': 0.91; '2013': 0.98 X-TMN: [RiCy/U2UWOEDSCAUHZxPTf5ojZJfd6+L] X-Originating-Email: [ycui@outlook.com] Content-Type: multipart/alternative; boundary="_83b8d853-ee8a-4897-bf76-89b6dd5ae296_" From: Frank Cui To: "python-list@python.org" Subject: RE: cascading python executions only if return code is 0 Date: Sun, 22 Dec 2013 16:35:43 -0300 Importance: Normal In-Reply-To: References: , , , , , MIME-Version: 1.0 X-OriginalArrivalTime: 22 Dec 2013 20:05:44.0350 (UTC) FILETIME=[326903E0:01CEFF51] 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: 186 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387742746 news.xs4all.nl 2832 [2001:888:2000:d::a6]:43657 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62550 --_83b8d853-ee8a-4897-bf76-89b6dd5ae296_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable > To: python-list@python.org > From: ned@nedbatchelder.com > Subject: Re: cascading python executions only if return code is 0 > Date: Sun=2C 22 Dec 2013 14:49:43 -0500 >=20 > On 12/22/13 2:10 PM=2C Frank Cui wrote: > > sorry=2C but what if I need to have different parameters in these funct= ions ? >=20 > Frank=2C welcome to the group. Common convention is to put your response= =20 > below the exiting message=2C so that the conversation continues down the = page. >=20 > (See my answer below... :) >=20 > > > > > > > To: python-list@python.org > > > From: breamoreboy@yahoo.co.uk > > > Subject: Re: cascading python executions only if return code is 0 > > > Date: Sun=2C 22 Dec 2013 19:31:21 +0000 > > > > > > On 22/12/2013 19:17=2C Roy Smith wrote: > > > > In article = =2C > > > > Frank Cui wrote: > > > > > > > >> hey guys=2C > > > >> I have a requirement where I need to sequentially execute a bunch= of > > > >> executions=2C each execution has a return code. the followed > > executions should > > > >> only be executed if the return code is 0. is there a cleaner or > > more pythonic > > > >> way to do this other than the following ? > > > >> if a() =3D=3D 0: if b() =3D=3D 0: c() > > > >> Thanks for your input. > > > >> frank > > > > > > > > Yup! Just do: > > > > > > > > a() or b() or c() > > > > > > > > The "or" operation has what's known as "short-circuit" semantics. = That > > > > means=2C if the first operand is true=2C it doesn't evaluate the s= econd > > > > operand. Just make sure that a()=2C b()=2C and c() all return some= thing > > > > which is true if they succeed and false otherwise. > > > > > > > > > > Really? :) > > > > > > -- > > > My fellow Pythonistas=2C ask not what our language can do for you=2C= ask > > > what you can do for our language. > > > > > > Mark Lawrence > > > > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > >=20 > The most Python-natural way to deal with your problem would be to have=20 > these functions not return status codes at all. Instead=2C have them=20 > raise an exception if something goes wrong. Then you can invoke them=20 > most naturally: >=20 > a() > b() > c() >=20 > Execution will continue as long as no exceptions are raised. If you=20 > need to deal with the failure case also=2C then: >=20 > try: > a() > b() > c() > except Exception as e: > # do something here >=20 > Depending on how you want to deal with failures=2C you'd probably use you= r=20 > own subclass of Exception=2C but this is the general idea. >=20 > Return codes can be awkward=2C especially in Python which has exception=20 > integrated so fully into the language=2C library=2C and culture. >=20 > --=20 > Ned Batchelder=2C http://nedbatchelder.com >=20 > --=20 > https://mail.python.org/mailman/listinfo/python-list Thanks for informing the rules. = --_83b8d853-ee8a-4897-bf76-89b6dd5ae296_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable


>=3B To: python-l= ist@python.org
>=3B From: ned@nedbatchelder.com
>=3B Subject: Re:= cascading python executions only if return code is 0
>=3B Date: Sun= =2C 22 Dec 2013 14:49:43 -0500
>=3B
>=3B On 12/22/13 2:10 PM=2C = Frank Cui wrote:
>=3B >=3B sorry=2C but what if I need to have diffe= rent parameters in these functions ?
>=3B
>=3B Frank=2C welcome = to the group. Common convention is to put your response
>=3B below t= he exiting message=2C so that the conversation continues down the page.
= >=3B
>=3B (See my answer below... :)
>=3B
>=3B >=3B>=3B >=3B
>=3B >=3B >=3B To: python-list@python.org
>= =3B >=3B >=3B From: breamoreboy@yahoo.co.uk
>=3B >=3B >=3B S= ubject: Re: cascading python executions only if return code is 0
>=3B = >=3B >=3B Date: Sun=2C 22 Dec 2013 19:31:21 +0000
>=3B >=3B &g= t=3B
>=3B >=3B >=3B On 22/12/2013 19:17=2C Roy Smith wrote:
&g= t=3B >=3B >=3B >=3B In article <=3Bmailman.4500.1387739297.18130.p= ython-list@python.org>=3B=2C
>=3B >=3B >=3B >=3B Frank Cui &l= t=3Bycui@outlook.com>=3B wrote:
>=3B >=3B >=3B >=3B
>=3B= >=3B >=3B >=3B>=3B hey guys=2C
>=3B >=3B >=3B >=3B>= =3B I have a requirement where I need to sequentially execute a bunch of>=3B >=3B >=3B >=3B>=3B executions=2C each execution has a retu= rn code. the followed
>=3B >=3B executions should
>=3B >=3B = >=3B >=3B>=3B only be executed if the return code is 0. is there a cl= eaner or
>=3B >=3B more pythonic
>=3B >=3B >=3B >=3B>= =3B way to do this other than the following ?
>=3B >=3B >=3B >= =3B>=3B if a() =3D=3D 0: if b() =3D=3D 0: c()
>=3B >=3B >=3B &g= t=3B>=3B Thanks for your input.
>=3B >=3B >=3B >=3B>=3B fra= nk
>=3B >=3B >=3B >=3B
>=3B >=3B >=3B >=3B Yup! Jus= t do:
>=3B >=3B >=3B >=3B
>=3B >=3B >=3B >=3B a() o= r b() or c()
>=3B >=3B >=3B >=3B
>=3B >=3B >=3B >= =3B The "or" operation has what's known as "short-circuit" semantics. That<= br>>=3B >=3B >=3B >=3B means=2C if the first operand is true=2C it= doesn't evaluate the second
>=3B >=3B >=3B >=3B operand. Just = make sure that a()=2C b()=2C and c() all return something
>=3B >=3B = >=3B >=3B which is true if they succeed and false otherwise.
>=3B= >=3B >=3B >=3B
>=3B >=3B >=3B
>=3B >=3B >=3B Re= ally? :)
>=3B >=3B >=3B
>=3B >=3B >=3B --
>=3B >= =3B >=3B My fellow Pythonistas=2C ask not what our language can do for y= ou=2C ask
>=3B >=3B >=3B what you can do for our language.
>= =3B >=3B >=3B
>=3B >=3B >=3B Mark Lawrence
>=3B >=3B = >=3B
>=3B >=3B >=3B --
>=3B >=3B >=3B https://mail.p= ython.org/mailman/listinfo/python-list
>=3B >=3B
>=3B >=3B>=3B
>=3B The most Python-natural way to deal with your problem wo= uld be to have
>=3B these functions not return status codes at all. = Instead=2C have them
>=3B raise an exception if something goes wrong.= Then you can invoke them
>=3B most naturally:
>=3B
>=3B= a()
>=3B b()
>=3B c()
>=3B
>=3B Execut= ion will continue as long as no exceptions are raised. If you
>=3B n= eed to deal with the failure case also=2C then:
>=3B
>=3B t= ry:
>=3B a()
>=3B b()
>=3B c()>=3B except Exception as e:
>=3B # do something here<= br>>=3B
>=3B Depending on how you want to deal with failures=2C you= 'd probably use your
>=3B own subclass of Exception=2C but this is th= e general idea.
>=3B
>=3B Return codes can be awkward=2C especia= lly in Python which has exception
>=3B integrated so fully into the l= anguage=2C library=2C and culture.
>=3B
>=3B --
>=3B Ned B= atchelder=2C http://nedbatchelder.com
>=3B
>=3B --
>=3B ht= tps://mail.python.org/mailman/listinfo/python-list

=
Thanks for informing the rules.
= --_83b8d853-ee8a-4897-bf76-89b6dd5ae296_--