Am Mittwoch, den 01.11.2006, 22:16 -0800 schrieb Dick Moores: > At 03:56 PM 11/1/2006, Andreas Kostyrka wrote: > >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)) > > OK, that works well. But why the 2?
2 is the usual error code for invalid cmdline parameters in the Unix world. Just an example here. > > BTW at the command line, "raise SystemExit(2)" produces a completely > silent exit. In Win IDE I get "SystemExit: 2". With IDLE: > > Traceback (most recent call last): > File "E:\Python25\dev\1unitConversion5a.py", line 425, in <module> > main() > File "E:\Python25\dev\1unitConversion5a.py", line 413, in main > s = formatAndCheckStringFromUser(s) > File "E:\Python25\dev\1unitConversion5a.py", line 342, in > formatAndCheckStringFromUser > s = stripResponseAndCheckForUserRequestForHelpOrToQuit(s) > File "E:\Python25\dev\1unitConversion5a.py", line 253, in > stripResponseAndCheckForUserRequestForHelpOrToQuit > raise SystemExit(2) > SystemExit: 2 > > If I can manage to use "break", all 3 exits are silent. Why is it > wrong to use "break" to exit? Because it does not: for i in xrange(50): for j in xrange(50, 100): if j == 77: break will not stop the program when it hits the break. But yes, there are no reason why you should not let your script just end. Andreas > > Dick Moores > > Dick Moores >
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor