[python-uk] Where is a Python program running?

Tim Golden mail at timgolden.me.uk
Mon Nov 19 16:48:35 CET 2007

Jeremy Nicoll - pyuk wrote:
> Under Windows XP, I could have a program running under python.exe or
> pythonw.exe or under IDLE.  How can I test within a python program which of
> these situations apply?  

(As a starter, you're better off asking this on the main Python
list; this is Python-UK which is quite low-volume and mostly used
for meetups etc. That said, here goes...)

I'm not sure if there's anything absolutely foolproof / x-platform.
A couple of starting points, though: the value of sys.executable
and the value of sys.stdout.

Try this program (which uses the pywin32 extensions):

import os, sys
import win32api

win32api.MessageBox (0, "%s\n%s" % (sys.executable, repr (sys.stdout)))

Save it as showme.py (or whatever) and run it under the different
environments you're considering. It gives enough to apply some sort
of metric, but it's hardly foolproof. As I say, ask the question on
the main Python list where there are more and smarter minds than mine.

I'm using the MessageBox functionality simple to get something showing
on-screen. Obviously this won't work x-platform, so you'd need to write
out to a file or use the logging module or something.


More information about the python-uk mailing list