How do I run a python script from within the IDLE interactive shell?
The following throws an error:
>>> python helloworld.py
SyntaxError: invalid syntax
How do I run a python script from within the IDLE interactive shell?
The following throws an error:
>>> python helloworld.py
SyntaxError: invalid syntax
EASIEST WAY
In IDLE, the following works :-
I don't know much about why it works, but it does..
For example:
Python2 Built-in function: execfile
It normally cannot be called with arguments. But here's a workaround:
Python3: alternative to exefile:
See https://stackoverflow.com/a/437857/739577 for passing global/local variables.
Deprecated since 2.6: popen
With arguments:
Advance usage: subprocess
With arguments:
Read the docs for details :-)
Tested with this basic
helloworld.py
:To run a python script in a python shell such as Idle or in a Django shell you can do the following using the exec() function. Exec() executes a code object argument. A code object in Python is simply compiled Python code. So you must first compile your script file and then execute it using exec(). From your shell:
I'm using Python 3.4. See the compile and exec docs for detailed info.
I tested this and it kinda works out :