Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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:code': 0.07; 'executed': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'a()': 0.16; 'b()': 0.16; 'cleaner': 0.16; 'cui': 0.16; 'guys,': 0.16; 'pythonic': 0.16; 'subject:python': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'hey': 0.18; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'received:(smtp server)': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'code': 0.31; 'bunch': 0.31; 'could': 0.34; 'requirement': 0.35; 'there': 0.35; 'thanks': 0.36; 'should': 0.36; 'easily': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'break': 0.61; 'extended': 0.61; 'more': 0.64; 'frank': 0.68 X-Virus-Scanned: OK Date: Sun, 22 Dec 2013 11:21:06 -0800 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: cascading python executions only if return code is 0 References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------030504020901080200080107" 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: 96 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387740403 news.xs4all.nl 2936 [2001:888:2000:d::a6]:52146 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62544 This is a multi-part message in MIME format. --------------030504020901080200080107 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 12/22/2013 10:37 AM, 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 > > This would seem to do the same as your code and could easily be extended to your "bunch" of things: exes = [a, b, c] for e in exes: if e() != 0: break --------------030504020901080200080107 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
On 12/22/2013 10:37 AM, 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


This would seem to do the same as your code and could easily be extended to your "bunch" of things:

exes = [a, b, c]

for e in exes:
  if e() != 0:
    break
--------------030504020901080200080107--