check if running under IDLE

Helmut Jarausch jarausch at skynet.be
Thu Aug 7 09:07:35 CEST 2003


Bob Gailer wrote:
> At 11:48 AM 8/6/2003 +0200, Helmut Jarausch wrote:
> [snip][
> To check a script accessing sys.argv I have to set it.
> 
>> Unfortunately the 'Run' pulldown menu of IDLE doesn't have an item
>> to set sys.argv as it's common with debuggers for C.
>>
>> Now in Python I can set  sys.argv within the script,
>> but forgetting to comment this out afterwards makes the
>> script wrong outside of IDLE
>>
>> So I'd like to say
>>
>> if __IDLE_IS_RUNNUNG__:
>>   sys.argv=['test','-a','/home/jarausch/BackUp']
>>
>> but I haven't work how to check if the script is running under IDLE's 
>> supervision.
> 
> 
> import sys
> __IDLE_IS_RUNNUNG__ = len(sys.modules) > 20
> 

Thanks for this idea. Just to report
a simple script

#!/usr/local/bin/python
import sys
print len(sys.modules)

prints 26 here (Python 2.3)

while under idle I get 117
so
__IDLE_IS_RUNNUNG__ = len(sys.modules) > 100

seems to be safe.

Helmut.

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany





More information about the Python-list mailing list