How to tell if invoked through IDLE or command line?

Robert D. Young Robert at AbilitySys.com
Mon May 2 15:09:55 EDT 2005


Poi-fect - thanks!

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


- Robert

"Michael Hoffman" <cam.ac.uk at mh391.invalid> wrote in message
news:d55tbe$r9o$1 at gemini.csx.cam.ac.uk...
> Robert D. Young wrote:
> > 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?)
> -- 
> Michael Hoffman





More information about the Python-list mailing list