A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/107000.html below:

Stop python

Stop pythonDave 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4