How to exit early?
pete at shinners.org
Mon Aug 12 18:51:32 CEST 2002
brobbins333 at shaw.ca wrote:
> The data input to my script may contain some that are special cases.
> If so, I want to process these in a special function, then exit
> without running the remainder of the script. What's the best way to do
> this? I need something like the 'exitsub' command in Visual Basic, or
> at least a way to jump to the end of the script and exit. Any
two ways to do it. first is the "exit" function from the sys module.
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 system
exit status will be one (i.e., failure).
for example, you would use it like this,
you can also raise the SystemExit exception, which i often find is nice and
raise SystemExit, "Exiting Early, whoops!"
More information about the Python-list