1

In my current directory, I have a foo1.py script and a directory named other with a foo2.py script inside.

Now:

I launch the interpreter, and using execfile I can launch both scripts. The thing is, when I edit and save foo1.py, I don't have to restart the interpreter, I just execfile again and it runs with my modifications, but the same doesn't happen with foo2.py. For the edits I made to foo2.py to take effect I have to quit and relaunch the interpreter, since even after saving it execfile('foo2.py') will run the same script as before...

This is annoying, as I wanted to constantly be editing and launching multiple scripts in sucession, who often depend on each other...

How can I make it soo that the interpreter sees my edits to foo2.py, without having to restart it?

Thanks!

Lanfear
  • 325
  • 2
  • 6

2 Answers2

1

Take a look at the documentation for the reload() function and the restrictions mentioned there; depending on your python version it is located in different modules, for 2.x it is predefined.

guidot
  • 5,095
  • 2
  • 25
  • 37
1

If you are using a "recent" Python, you could try the following syntax compatible with Python 2.6, 2.7 and 3.x

with open('foo2.py') as file:
    exec(compile(file.read(), 'foo2.py', 'exec'))
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252