blues
blues

Reputation: 5195

start the python IDLE from a python script

How can i start the Python-IDLE from a python script in a way so that all the variables and functions that previously have been declared in the script are than known in the IDLE?

Upvotes: 3

Views: 1023

Answers (1)

Sasha B
Sasha B

Reputation: 1928

You can run IDLE from the command-line using:

idle.py [-c command] [-d] [-e] [-s] [-t title] [arg] ...

-c command  run this command
-d          enable debugger
-e          edit mode; arguments are files to be edited
-s          run $IDLESTARTUP or $PYTHONSTARTUP first
-t title    set title of shell window

Also:

Upon startup with the -s option, IDLE will execute the file referenced by the environment variables IDLESTARTUP or PYTHONSTARTUP. Idle first checks for IDLESTARTUP; if IDLESTARTUP is present the file referenced is run. If IDLESTARTUP is not present, Idle checks for PYTHONSTARTUP. Files referenced by these environment variables are convenient places to store functions that are used frequently from the Idle shell, or for executing import statements to import common modules. (From the docs: http://docs.python.org/library/idle.html)

So you could set either $IDLESTARTUP or $PYTHONSTARTUP to a python file with the variables you want to declare, and they will be available from within IDLE when it starts.

You could start IDLE from a Python script this way by using the os.system command (or subprocess.Popen) to run the command above.

Upvotes: 3

Related Questions