3

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?

0

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This can be done much easier with from idlelib import PyShell; PyShell.main(). It doesn't preserve the current environment, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.