Search code examples
pythoninteractivemode

Is there a possibility to execute a Python script while being in interactive mode


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.


Solution

  • Use execfile('script.py') but it only work on python 2.x, if you are using 3.0 try exec(open('script.py').read())