Programmatically stop execution of python script? [duplicate]
raise SystemExit(0) instead of going to all the trouble to
import sys; sys.exit(0).
sys.exit(). From Python's docs:
import sysprint sys.exit.__doc__exit([status])Exit the interpreter by raising SystemExit(status).If the status is omitted or None, it defaults to zero (i.e., success).If the status is numeric, it will be used as the system exit status.If it is another kind of object, it will be printed and the systemexit status will be one (i.e., failure).
So, basically, you'll do something like this:
from sys import exit# Code!exit(0) # Successful exit