How to exit the main script in Python

Sean 'Shaleh' Perry shalehperry at attbi.com
Fri Aug 16 15:27:29 EDT 2002


On 16-Aug-2002 Richard Kessler wrote:
> I have a simple script that calls a bunch of functions to do things. 
> Sometimes I need to simply exit the main script mid way but I can't find 
> the syntax. 'Return' does not work outside of a function. 'Break' must 
> be in a loop...etc.
> 
> The VB counter part would be 'end'.
> 
> Many thanks in advance.
> 

two choices:

import sys
sys.exit(code)

or

raise SystemExit, code

sys.exit() actually works by raising the exception.




More information about the Python-list mailing list