Path: csiph.com!usenet.pasdenom.info!aioe.org!newsfeed.x-privat.org!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:IDLE': 0.04; 'interpreter': 0.05; 'detect': 0.07; 'linux,': 0.07; 'advance': 0.07; 'any)': 0.09; 'subject:How': 0.10; '"running': 0.16; '(apologies': 0.16; 'googling': 0.16; 'ideally,': 0.16; 'idle.': 0.16; 'received:74.208.4.195': 0.16; 'spyder,': 0.16; 'subject:under': 0.16; 'usenet': 0.16; 'wrote:': 0.18; 'fit': 0.20; 'seems': 0.21; 'print': 0.22; 'header:User-Agent:1': 0.23; 'environment': 0.24; 'suggested': 0.26; 'this:': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "i'm": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'this.': 0.32; 'open': 0.33; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'connection': 0.35; 'but': 0.35; 'subject:?': 0.36; 'example,': 0.37; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'tell': 0.60; 'such': 0.63; 'skip:n 10': 0.64; 'believe': 0.68; 'received:74.208': 0.68; 'detecting': 0.84; 'subject:tell': 0.84 Date: Fri, 05 Apr 2013 07:04:35 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How do I tell if I'm running under IDLE? References: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <515e99c8$0$30001$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:S2tVVruEV5l0+r37Ygt5CoTY6sKgxUyvrOP6KfRDUNZ Qi4ifiOfwE+QXGHRw6iaEc20TTrzB7f58g3Y3Y2pOvvPvuUrSF w1S0PUd0KMeTUbGatdREIUgHNRTBtrIyTQT04lscMEcDe5+TPJ WBDJfycRVqAAAGWA7J96hy33RpO7raZASLDjcC/uS9jVHXQPFd kb151ibLbN6PNkBU3UlGapVkBslGAn/CYo8k3NTdkg3zJcpg0y uwNyHlZzNHicXx69OFVITR/WbcnvZBYfC/4Xqvzr1ySGGf/Vah 3jRHhUjcnd+Gb0rOELrCr70aEE17RGnas/OHw6ZJJx65bCLnQ= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365159902 news.xs4all.nl 6965 [2001:888:2000:d::a6]:56632 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42803 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