[Tutor] Using sys.exit()

Alan Gauld alan.gauld at btinternet.com
Tue Oct 31 09:14:46 CET 2006

"Dick Moores" <rdm at rcblue.com> wrote
> I'd like to know how to use sys.exit() to quit a program.

I see that you already figured that out.
You can also quit by raising SystemExit, which is
what sys.exit does... but you don't need to import sys...

> Is there a way to use it the way I want to? Maybe with an argument?

You can use an argument if you want to pass an error value
back to the OS. This is good practice if your script might be
used in a batch file or shell script

> I'm writing a script, which in a couple of places I can't
> use "break" to quit.

break is not intended to quit programs, break is intended
to quit loops. To exit a program you should use sys.exit()
and if its an abnormal exit provide an argument.

Alan G. 

More information about the Tutor mailing list