Programmatically stop execution of python script?


Question

Possible Duplicate:
Terminating a Python script

Is it possible to stop execution of a python script at any line with a command?

Like

some code

quit() # quit at this point

some more code (that's not executed)
1
193
5/23/2017 12:02:47 PM

Accepted Answer

sys.exit() will do exactly what you want.

import sys
sys.exit("Error message")
316
3/31/2015 1:35:40 AM

You could raise SystemExit(0) instead of going to all the trouble to import sys; sys.exit(0).


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon