Am Mittwoch, den 01.11.2006, 15:43 -0800 schrieb Dick Moores: > At 12:14 AM 10/31/2006, Alan Gauld wrote: > > >"Dick Moores" <[EMAIL PROTECTED]> 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?
raise SystemExit(2) is equal to sys.exit(2) (actually sys.exit(2) just raises SystemExit(2)) >>> try: ... import sys ... sys.exit(2) ... except SystemExit, v: ... print v ... 2 And you don't need to import sys, because SystemExit is a standard exception that are builtin, available everywhere. Andreas > > > > 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@python.org > >http://mail.python.org/mailman/listinfo/tutor > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor