how to stop a function execution like...

pdpi pdpinheiro at gmail.com
Tue Jun 16 14:55:35 CEST 2009


On Jun 16, 12:45 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> Gaudha wrote:
> > Is there any built-in function to stop execution of a function similar
> > to stop the program execution by sys.exit?
> > In the example below, I want to skip statement 2... if the 'if'
> > condition is satisfied.
> > Don't advice me to put statement 2 in 'else' block. That's not my
> > intention.
>
> Why not? It's from all you tell us perfectly the right thing to do.
>

If I understood his post correctly, it's because he really wants to
exit the function early.
If that is the case, in his real situation rather than the tiny
example he posted, using the else clause would translate into:

def funct(params):
  if a:
    something
  else:
    rest of the function
    goes here
    and it goes on for a while
    so you just burnt through
    an indentation level needlessly

Now we can have a nice philosophical discussion about how using the
else version makes the execution outline more obvious :)



More information about the Python-list mailing list