Stopping Execution

Fredrik Lundh fredrik at pythonware.com
Thu Nov 10 16:45:20 EST 2005


James Colannino wrote:

> Hey everyone.  I remember from my C programming that I can either use
> the exit() or return() functions to end execution of the main code
> block.  My question is, is there a way for me to do this in Python?  I
> know there has to be, but I can't for the life of me figure out what it
> is.  The reason I ask is that I need to conditionally end a script I'm
> writing at various places.  Thanks in advance.

the usual way:

    sys.exit() # or "raise SystemExit"

    http://docs.python.org/lib/module-sys.html#l2h-343

hard exit, for special cases:

    os._exit()

    http://docs.python.org/lib/os-process.html#l2h-1656

</F>






More information about the Python-list mailing list