Stop Python from exiting upon error in Windows

Robert at AbilitySys.com Robert at AbilitySys.com
Tue Jul 15 18:03:35 EDT 2003


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...

- Robert

"Peter Hansen" <peter at engcorp.com> wrote in message
news:3F142B51.94C898BC at engcorp.com...
> Robert at AbilitySys.com wrote:
> >
> > Ok, I figured out the IDLE block indent (duh - RTFMenu), and now it
works
> > great in DOS. Again, thanks to all who helped.
> >
> > However, I'd still like to know how to determine what environment I'm
> > running under inside my code. Any suggestions?
>
> I doubt if there's any particular way to do it consistently.  In
> principle one could write a cute module which would be able to check
> the "signature" of the environment to figure it all out.  Check if
> certain modules are in __builtins__ to see if you are running inside
> an application that uses Python for scripting, check for sys.argv[0]
> to learn whether you were launched in a way that suggests running as
> a script with python.exe, etc.
>
> It's probably not a great idea to write anything which depends on this
> however, and it sounds like more time than it's worth.
>
> -Peter






More information about the Python-list mailing list