Re: check if running under IDLE

Discussion in 'Python' started by Helmut Jarausch, Aug 7, 2003.

  1. 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
    Helmut Jarausch, Aug 7, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hshdude
    Replies:
    12
    Views:
    1,040
    Dimitri Maziuk
    Nov 4, 2004
  2. bronby
    Replies:
    1
    Views:
    592
    Andrew Thompson
    Jul 15, 2005
  3. Bo Peng
    Replies:
    1
    Views:
    458
    Bo Peng
    Jan 9, 2006
  4. Badger_1610
    Replies:
    2
    Views:
    547
    Badger_1610
    Sep 1, 2010
  5. Steven D'Aprano

    How do I tell if I'm running under IDLE?

    Steven D'Aprano, Apr 5, 2013, in forum: Python
    Replies:
    6
    Views:
    85
    Dave Angel
    Apr 7, 2013
Loading...

Share This Page