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!

asked Apr 29, 2014 at 8:14

2 Answers 2

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.

answered Apr 29, 2014 at 8:38
Sign up to request clarification or add additional context in comments.

Comments

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'))
answered Apr 29, 2014 at 8:52

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.