win32: Leaving Dos Box open
Duncan Booth
duncan at NOSPAMrcp.co.uk
Tue Jul 9 10:01:54 EDT 2002
Thomas Guettler <zopestoller at thomas-guettler.de> wrote in
news:3D2AE438.9030205 at thomas-guettler.de:
> Hi!
>
> How can the dos box be left open when I run foo.py from
> the windows explorer and there is a syntax error?
>
> thomas
>
>
Try something like this:
---- error.py ---
import sys
def excepthook(t,v,tr, old=sys.excepthook):
old(t,v,tr)
raw_input("Press return to exit")
sys.excepthook = excepthook
x = 3/0
print "Done"
---- end of error.py ---
Copy the top 5 lines somewhere near the top of your own script.
Alternatively wrap a try:except: handler around the main loop of your
script. I sometimes use code like this:
if __name__ == '__main__':
try:
# main program code goes here...
main()
except:
# In case of emergency, lets debug!
import pdb, sys, traceback
sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info()
traceback.print_last()
pdb.pm()
Which not only keeps the window open, but throws you into a debugger for
good measure.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list