[Tutor] Using sys.exit()

Dick Moores rdm at rcblue.com
Thu Nov 2 10:05:42 CET 2006


At 11:09 PM 11/1/2006, Luke Paireepinart wrote:
>>If I can manage to use "break", all 3 exits are silent. Why is it 
>>wrong to use "break" to exit?
>>
>'break' doesn't exit.  It ends a loop.
>It's not wrong to use a 'break' to exit a loop.  That's what it's there for.
>But what if you were doing something after the loop?
>'break' wouldn't help you there.

Yes, I realize that. But what if I'm not doing anything after the 
loop? In that case is there anything wrong with using break to end 
the script? I'm getting the idea from the responses that there IS 
something wrong, but I don't see what it is.

>A SystemExit immediately ends the program at that call
>(unless you catch the exception :)
>
>The reason the exits with break are 'silent'
>is because no exceptions are occurring.

But that's exactly what I want--a silent exit.

>SystemExit is an exception.
>There's nothing wrong with using it.
>You could raise an IOError if you wanted.

Please explain how to do that, and why I would want to.

Thanks,

Dick





More information about the Tutor mailing list