Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62550

RE: cascading python executions only if return code is 0

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 <ycui@outlook.com>
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; '&gt;&gt;': 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; '&gt;': 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 <ycui@outlook.com>
To "python-list@python.org" <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 <l97fob$p68$1@ger.gmane.org>
References <l97elv$etg$1@ger.gmane.org> <BAY176-W23B383D8FC920EE78C424DAC60@phx.gbl>,<l97fob$p68$1@ger.gmane.org>
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 <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.4507.1387742746.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

> To: python-list@python.org
> From: ned@nedbatchelder.com
> Subject: Re: cascading python executions only if return code is 0
> Date: Sun, 22 Dec 2013 14:49:43 -0500
> 
> On 12/22/13 2:10 PM, Frank Cui wrote:
> > sorry, but what if I need to have different parameters in these functions ?
> 
> Frank, welcome to the group.  Common convention is to put your response 
> below the exiting message, so that the conversation continues down the page.
> 
> (See my answer below... :)
> 
> >
> >
> >  > To: python-list@python.org
> >  > From: breamoreboy@yahoo.co.uk
> >  > Subject: Re: cascading python executions only if return code is 0
> >  > Date: Sun, 22 Dec 2013 19:31:21 +0000
> >  >
> >  > On 22/12/2013 19:17, Roy Smith wrote:
> >  > > In article <mailman.4500.1387739297.18130.python-list@python.org>,
> >  > > Frank Cui <ycui@outlook.com> 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
> >  >
> >  > --
> >  > https://mail.python.org/mailman/listinfo/python-list
> >
> >
> 
> The most Python-natural way to deal with your problem would be to have 
> these functions not return status codes at all.  Instead, have them 
> raise an exception if something goes wrong.   Then you can invoke them 
> most naturally:
> 
>      a()
>      b()
>      c()
> 
> Execution will continue as long as no exceptions are raised.  If you 
> need to deal with the failure case also, then:
> 
>      try:
>          a()
>          b()
>          c()
>      except Exception as e:
>          # do something here
> 
> Depending on how you want to deal with failures, you'd probably use your 
> own subclass of Exception, but this is the general idea.
> 
> Return codes can be awkward, especially in Python which has exception 
> integrated so fully into the language, library, and culture.
> 
> -- 
> Ned Batchelder, http://nedbatchelder.com
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Thanks for informing the rules. 		 	   		  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

cascading python executions only if return code is 0 Frank Cui <ycui@outlook.com> - 2013-12-22 15:37 -0300
  Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 14:17 -0500
    Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-22 19:31 +0000
      Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 15:05 -0500
        Re: cascading python executions only if return code is 0 Cameron Simpson <cs@zip.com.au> - 2013-12-23 08:39 +1100
          Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 16:53 -0500
            Re: cascading python executions only if return code is 0 Cameron Simpson <cs@zip.com.au> - 2013-12-23 09:11 +1100
            Re: cascading python executions only if return code is 0 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-22 22:10 -0500
            Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 14:22 +1100
            Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 03:43 +0000
            Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 14:45 +1100
            Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 03:54 +0000
            Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 14:59 +1100
    RE: cascading python executions only if return code is 0 Frank Cui <ycui@outlook.com> - 2013-12-22 16:10 -0300
    Re: cascading python executions only if return code is 0 Ned Batchelder <ned@nedbatchelder.com> - 2013-12-22 14:49 -0500
      Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-23 00:08 +0000
    RE: cascading python executions only if return code is 0 Frank Cui <ycui@outlook.com> - 2013-12-22 16:35 -0300
      Re: cascading python executions only if return code is 0 Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-23 13:30 +1300
  Re: cascading python executions only if return code is 0 Rick Johnson <rantingrickjohnson@gmail.com> - 2013-12-22 14:27 -0800
    RE: cascading python executions only if return code is 0 Frank Cui <ycui@outlook.com> - 2013-12-22 19:14 -0300
    Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 09:51 +1100
    Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-22 23:02 +0000
      Re: cascading python executions only if return code is 0 Rick Johnson <rantingrickjohnson@gmail.com> - 2013-12-22 15:57 -0800
        Re: cascading python executions only if return code is 0 Ned Batchelder <ned@nedbatchelder.com> - 2013-12-23 07:27 -0500
        Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 12:44 +0000
  Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-23 00:25 +0000
    Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 20:24 -0500
      Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 12:35 +1100
      Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-23 13:33 +1100
        Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 14:09 +1100
        Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 23:57 -0500
          Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 16:09 +1100
          Re: cascading python executions only if return code is 0 Ethan Furman <ethan@stoneleaf.us> - 2013-12-23 04:45 -0800
            Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-23 10:10 -0500
              Re: cascading python executions only if return code is 0 Ethan Furman <ethan@stoneleaf.us> - 2013-12-23 08:00 -0800
                Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-26 20:37 -0500
                Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 12:44 +1100
                Re: cascading python executions only if return code is 0 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-26 21:20 -0500
                Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 13:27 +1100
                Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-26 23:29 -0500
                Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 15:40 +1100
                Re: cascading python executions only if return code is 0 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-27 11:15 -0500
                Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-27 11:42 -0500
                Re: cascading python executions only if return code is 0 Rustom Mody <rustompmody@gmail.com> - 2013-12-27 22:39 +0530
                Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-28 08:24 +1100
                Re: cascading python executions only if return code is 0 pecore@pascolo.net - 2013-12-28 00:59 +0100
                Re: cascading python executions only if return code is 0 Gene Heskett <gheskett@wdtv.com> - 2013-12-27 19:12 -0500
                Re: cascading python executions only if return code is 0 Tim Chase <python.list@tim.thechases.com> - 2013-12-26 20:50 -0600
                Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-27 15:39 +1100
                Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 15:45 +1100
                Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-27 00:05 -0500
                Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 16:15 +1100
                Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-27 00:41 -0500
                Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-27 18:00 +0000
                Re: cascading python executions only if return code is 0 Grant Edwards <invalid@invalid.invalid> - 2013-12-30 17:36 +0000
              Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-24 04:05 +1100
                Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-23 11:03 -0800
                Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-24 06:12 +1100
                RE: cascading python executions only if return code is 0 Nick Cash <nick.cash@npcinternational.com> - 2013-12-23 19:31 +0000
                Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-24 14:41 +1100
                Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-23 22:58 -0500
              Re: cascading python executions only if return code is 0 Peter Otten <__peter__@web.de> - 2013-12-23 18:45 +0100
          Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 13:20 +0000
        Re: cascading python executions only if return code is 0 Ethan Furman <ethan@stoneleaf.us> - 2013-12-23 04:38 -0800
        Re: cascading python executions only if return code is 0 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-23 10:12 -0500
          Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-24 04:13 +1100
        Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 15:22 +0000

csiph-web