How to tell if invoked through IDLE or command line?

  • Thread starter Robert D. Young
  • Start date
R

Robert D. Young

I've probably asked this before, but how can I tell within the program I'm
running if the .py files was involved by "run module" in IDLE or by using
the .py assoication with the python.exe program? I'd like to prevent running
under certain circumstances, or pop-up warnings, or change character
displays (some look different when run under IDLE).

- Robert
 
M

Michael Hoffman

Robert said:
I've probably asked this before, but how can I tell within the program I'm
running if the .py files was involved by "run module" in IDLE or by using
the .py assoication with the python.exe program? I'd like to prevent running
under certain circumstances, or pop-up warnings, or change character
displays (some look different when run under IDLE).

sys.modules.keys() contains "idlelib" is a simple way of doing it,
assuming you never import idlelib otherwise (and why would you?)
 
R

Robert D. Young

Poi-fect - thanks!

import sys
if sys.modules.has_key("idlelib"):
print "Running under idle"
else:
print "Not running under idle"


- Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top