Stop python
Dave LeBlanc
whisper at oz.net
Mon Apr 16 13:38:10 EDT 2001
How would this terminate the parsing of a Python program (as opposed
to execution)?
Dave LeBlanc
On Mon, 16 Apr 2001 10:47:10 +0200, Steve Purcell
<stephen_purcell at yahoo.com> wrote:
>David V. wrote:
>> Is it possible to stop parsing python program at some point, for
>> example, like in shell script using ‘exit’?
>
>Yes,
>
> import sys
> sys.exit()
>
>Usually, though, you should instead structure your program into functions
>that call each other. The program would exit when the top-level
>function exits:
>
>
> def main(): # top-level function
> do_something() # another function
> if not more_things_to_do():
> return # the program exits by returning from the
> # top-level function
> do_more_things()
>
> if __name__ == '__main__': # if this file is run as a script
> main() # start the top-level function
>
>
>-Steve
>
>--
>Steve Purcell, Pythangelist
>Get testing at http://pyunit.sourceforge.net/
>Any opinions expressed herein are my own and not necessarily those of Yahoo
>
More information about the Python-list
mailing list