Stop Python from exiting upon error in Windows

Conrad zneptune321 at zexcite.zcom
Mon Jul 14 23:19:40 EDT 2003


Years ago, Nostradamus predicted that on Mon, 14 Jul 2003 20:06:14 -0700,
Tom Plunket would write, saying:

> Robert wrote:
> 
>> How can I stop the Python interpreter from exiting when an error occurs?
> 
> create a batchfile, tell Windows that the association of Python
> files is to that batch file, and put this in the file:
> 
> python.exe %1
> pause
> 
> 
> Or- catch the error in your mainline, and do a sys.raw_input()
> call on exception.
> 
> -tom!

Or the third, and admittedly brute force solution 
I use is to fire up the DOS shell, (click on START, 
then RUN, then type "command"). Depending on which 
Win you're running, you may want to run DOSKEY, 
which lets you cursor back up to previous commands.

Once you've got the command window up (and doskeyed),
cd to your python source directory, and type in
something like *C:\python22\python.exe mypythonfile.py*
(leave out the *s and be sure python is in the same
place on your machine.)

This doesn't keep the python interpreter from exiting, 
but it does keep the DOS window open to let you see 
your error messages.

I admit it's ugly, but hey, I mostly develop in
FreeBSD and Linux, where the CLI is your buddy ;-)

Conrad






More information about the Python-list mailing list