Normally you can execute a Python script for example: python myscript.py
, but if you are in the interactive mode, how is it possible to execute a Python script on the filesystem?
>>> exec(File) ???
It should be possible to execute the script more than one time.
You can run any system command using python:
You might want to look into IPython, a more powerful interactive shell. It has various "magic" commands including
%run script.py
(which, of course, runs the script and leaves any variables it defined for you to examine).The easiest way to do it is to use the
os
module:In fact
os.system('cmd')
to run shell commands. Hope it will be enough.You can also use the
subprocess
module. Something like:Use execfile('script.py') but it only work on python 2.x, if you are using 3.0 try this
import file
without the .py extension will do it, however__name__
will not be"__main__"
so if the script does any checks to see if it's being run interactively you'll need to bypass them.Alternately, if you're wanting to have a look at the environment after the script runs try
python -i script.py
EDIT: To load it again
file = reload(file)