How to exit early?

François Pinard pinard at iro.umontreal.ca
Mon Aug 12 18:57:50 CEST 2002


[brobbins333 at shaw.ca]

> I want to [...] exit without running the remainder of the script.
> What's the best way to do this?

Suppose you want to exit with status code 13.  You may use either:

    raise SystemExit, 13

or maybe:

    import sys
    sys.exit(13)

If you want status 0, representing no error, you may prefer to write
either of:

    raise SystemExit

    import sys
    sys.exit()

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list