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

Jeremy Nicoll - pyuk jn.ml.pyuk.93 at wingsandbeaks.org.uk
Mon Nov 19 14:20:30 CET 2007

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?  

At the moment, for example, I have a program which runs under python.exe
because it might produce some output - certainly while writing it there's
quite a few inline print statements.  I set a flag as soon as any output is
produced (whether error messages, intentional trace statements, whatever),
and at the end of the program if the flag is set then execute:

  toldtostop = ""
  while toldtostop.upper() <> "QQ":
     toldtostop = raw_input("\nEnter QQ to close window...")

If nothing has been printed that's not done, and the console window just
shuts.  If I were to use pythonw instead, presumably I'd need to find some
other way to display output?

If I test these programs under IDLE the toldtostop/QQ stuff is just a
nuisance, so I'd prefer to be able not to have it run.  I suppose that also
applied to a.n.other.ide - so is there a general way to test if any ide is
in use?

There's a possibility that some of what I'm writing may also get run on Mac
and/or Linux/Unix systems.  Do whatever methods I might use to test what's
going on work cross-platform?

Jeremy C B Nicoll - my opinions are my own.

More information about the python-uk mailing list