"Jason MacFiggen" <jmacfig...@gmail.com> wrote

I was wondering how can I change sys.exit so if you use command line to run the program. it prompts a message asking if the user wants to exit instead
of automatically just exiting?

Don't just use sys.exit use a try/except SystemExit...
import sys
try:
...    sys.exit()
... except SystemExit:
...    print 'caught exit'
...    raise
...
caught exit

However thats usually the wrong way to do it.
Better to have your program exit naturally and have the control logic in
the code control when it finishes.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to