Stop Python from exiting upon error in Windows

Bob Gailer bgailer at
Wed Jul 16 18:48:39 CEST 2003

At 03:03 PM 7/15/2003 -0700, Robert at wrote:

>The trouble there is that sys.argv[0] is consistently the file name of the
>script running, whether I do it with python.exe or via IDLE/Run Script. (I
>actually use it to open the script within itself and copy itself out to an
>audit log for a record of what code created the script's results)
>You're right, it's probably not worth it since it just adds a "press enter"
>to the output when I run my script in IDLE (where I don't actually need the
>pause). I just thought the cognoscenti out here might have run across a
>nifty trick for determining if it was python.exe/PythonWin/whatever since I
>couldn't find such a thing in the books or manuals I have...

The length of sys.modules can help. The 2.2.2 interpreter __import__s 15 
modules; IDLE adds 73, PythonWin adds 213. So code like this might suffice, 
leaving room for future changes.

import sys
if len(sys.modules) < 50: ... # raw interpreter
elif len(sys.modules) < 200: ... # IDLE
else: ... # PythonWin

Bob Gailer
bgailer at
303 442 2625
-------------- next part --------------

Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003

More information about the Python-list mailing list