Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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; 'from:addr:yahoo.co.uk': 0.04; 'true,': 0.05; 'subject:code': 0.07; 'executed': 0.09; 'lawrence': 0.09; 'means,': 0.09; 'operand': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'language.': 0.14; '"or"': 0.16; 'a()': 0.16; 'b()': 0.16; 'cleaner': 0.16; 'cui': 0.16; 'guys,': 0.16; 'pythonic': 0.16; 'really?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'subject:python': 0.16; 'followed': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'hey': 0.18; 'header:User- Agent:1': 0.23; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'code': 0.31; 'bunch': 0.31; 'something': 0.35; 'requirement': 0.35; 'there': 0.35; 'false': 0.36; 'otherwise.': 0.36; 'thanks': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'first': 0.61; 'our': 0.64; 'more': 0.64; 'frank': 0.68; 'smith': 0.68; 'evaluate': 0.72; 'article': 0.77; 'do:': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: cascading python executions only if return code is 0 Date: Sun, 22 Dec 2013 19:31:21 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-146-15-252.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387740695 news.xs4all.nl 2848 [2001:888:2000:d::a6]:58454 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62546 On 22/12/2013 19:17, Roy Smith wrote: > In article , > Frank Cui wrote: > >> hey guys, >> I have a requirement where I need to sequentially execute a bunch of >> executions, 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() == 0: if b() == 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, if the first operand is true, it doesn't evaluate the second > operand. Just make sure that a(), b(), and c() all return something > which is true if they succeed and false otherwise. > Really? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence