[Tutor] sys.exit help
alan.gauld at btinternet.com
Mon Aug 2 02:20:51 CEST 2010
"Jason MacFiggen" <jmacfiggen at gmail.com> wrote
>I was wondering how can I change sys.exit so if you use command line
> the program. it prompts a message asking if the user wants to exit
> of automatically just exiting?
Don't just use sys.exit use a try/except SystemExit...
>>> import sys
... except SystemExit:
... print 'caught exit'
However thats usually the wrong way to do it.
Better to have your program exit naturally and have the control logic
the code control when it finishes.
Author of the Learn to Program web site
More information about the Tutor