check if running under IDLE

Helmut Jarausch jarausch at igpm.rwth-aachen.de
Wed Aug 6 05:48:02 EDT 2003


Peter Abel wrote:
> Helmut Jarausch <jarausch at skynet.be> wrote in message news:<3f2ec16b$0$285$ba620e4c at reader0.news.skynet.be>...
> 
>>Hi,
>>
>>I'd like to check a script which needs sys.argv
>>I haven't seen a method to set this when running the script
>>in IDLE's shell or editor window.
>>The only way I've found is to assign (test values)
>>to sys.argv but only if the script is running under IDLE
>>
>>Is there a mean either to set sys.argv without modifying
>>the script or to check if the script is running under IDLE's
>>control.
>>
>>Thanks for a hint,
>>
>>Helmut Jarausch
>>
>>Lehrstuhl fuer Numerische Mathematik
>>RWTH - Aachen University
>>D 52056 Aachen, Germany
> 
> 
> 
> I doen't think that your problem is to know if
> you're running under Idle or PythonWin or Pythonshell
> or ..
> I think your problem is to know if there are command line
> parameters passed to your script or not. And this is simply
> done by:
> if len(sys.argv) > 1:
>   do_something_with(sys.argv[1:])
> else:
>   do_something_else_with_explicit(['Para_1','Para_2', ... ,'Para_Last']
> 
> Hope I'm not wrong.

I think so.

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.

Thanks,
Helmut.

-- 
Helmut Jarausch

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





More information about the Python-list mailing list