washboardalex
washboardalex

Reputation: 89

Open Python IDLE with flags

I am currently working through MIT's OpenCourseWare subject "Introduction to Electrical Engineering and Computer Science 1", and am up to the module on the Signals class.

I am having trouble with using the plotting method in the class. The course material states:

"Be sure to start idle with the -n flag, if you want to make plots of signals from inside idle."

This is the first time in my coding education that I have come across starting a program with a flag. I think I understand the general gist of what it entails and have played around with opening IDLE using the windows command prompt.

However, I have had no luck so far and notwithstanding my guesses don't really know what I'm doing.

Would someone be able to explain how exactly I can do this and more generally how opening programs with flags works?

I have done some google/stack searches but have only come up with stack overflow material assuming the knowledge I'm looking for in answering other questions or information discussing flags in the context of coding functions in python itself (myFlag=False or whatever).

I am using python 2.6.

Many thanks in advance. Apologies if the question is silly or obvious, I'm quite new to coding.

Upvotes: 0

Views: 852

Answers (1)

ShpielMeister
ShpielMeister

Reputation: 1455

idle is just another program run by the OS. just like grep or ls can have flags so can idle. flags just make it easier and more efficient to parse the parameters on the command line. on macos hre are the options. windows will be similar

└─╼ idle -h

USAGE: idle  [-deins] [-t title] [file]*
       idle  [-dns] [-t title] (-c cmd | -r file) [arg]*
       idle  [-dns] [-t title] - [arg]*

  -h         print this help message and exit
  -n         run IDLE without a subprocess (see Help/IDLE Help for details)

The following options will override the IDLE 'settings' configuration:

  -e         open an edit window
  -i         open a shell window

The following options imply -i and will open a shell:

  -c cmd     run the command in a shell, or
  -r file    run script from file

  -d         enable the debugger
  -s         run $IDLESTARTUP or $PYTHONSTARTUP before anything else
  -t title   set title of shell window

A default edit window will be bypassed when -c, -r, or - are used.

[arg]* are passed to the command (-c) or script (-r) in sys.argv[1:].

Examples:

idle
        Open an edit window or shell depending on IDLE's configuration.

idle foo.py foobar.py
        Edit the files, also open a shell if configured to start with shell.

idle -est "Baz" foo.py
        Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell
        window with the title "Baz".

idle -c "import sys; print sys.argv" "foo"
        Open a shell window and run the command, passing "-c" in sys.argv[0]
        and "foo" in sys.argv[1].

idle -d -s -r foo.py "Hello World"
        Open a shell window, run a startup script, enable the debugger, and
        run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in
        sys.argv[1].

echo "import sys; print sys.argv" | idle - "foobar"
        Open a shell window, run the script piped in, passing '' in sys.argv[0]
        and "foobar" in sys.argv[1].

Upvotes: 0

Related Questions