[Tutor] Using sys.exit()

Dick Moores rdm at rcblue.com
Thu Nov 2 00:43:36 CET 2006


At 12:14 AM 10/31/2006, Alan Gauld wrote:

>"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...

I'm afraid I don't know what you mean. How do I raise SystemExit, and 
why don't I 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

So what should that value be? But if answering is a lot of bother, 
don't, because I don't (yet) use python to write either batch files 
or shell scripts.

> > 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.

Of course, I've been using break to exit only when it works. Why is 
it wrong to do so?

Thanks,

Dick Moores


>Alan G.
>
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list