How do I tell if I'm running under IDLE?
Dave Angel
davea at davea.name
Fri Apr 5 07:04:35 EDT 2013
On 04/05/2013 05:30 AM, Steven D'Aprano wrote:
> (Apologies in advance if you get multiple copies of this. My Usenet
> connection seems to be having a conniption fit at the moment.)
>
> I'm looking for an official way to tell what interpreter (if any) is
> running, or at least a not-too-horrible unofficial way.
>
> Googling comes up with a number of hacks for detecting IDLE. Some of them
> are terrible. For example, I can't believe that somebody actually
> suggested this:
>
> if len(sys.modules) > 20:
> print "running under IDLE"
>
>
> This one is better, but still not exactly what I consider great:
>
> sys.stdin.__class__.__module__.startswith('idlelib')
>
>
>
> Ideally, I'd like to detect any arbitrary environment such as Spyder,
> IPython, BPython, etc., but will settle for just IDLE.
>
>
>
Are you open to OS-specific techniques? For example, on Linux, you
could learn things from ps aux.
--
DaveA
More information about the Python-list
mailing list