2

I'm working from inside an ipython shell and often need to reload the script files that contain my functions-under-construction.

Inside my main.py I have:

def myreload(): execfile("main.py") execfile("otherfile.py")

Calling myreload() works fine if I have already ran in the same ipython session the execfile commands directly.

However, for some reason, if the session is fresh and I just called execfile("main.py"), then myreload() doesn't actually make the functions from inside otherfile.py available. It doesn't throw any error though.

Any ideas?

asked Aug 22, 2010 at 5:54

2 Answers 2

2

Functions create a new scope. execfile() runs the script in the current scope. What you are doing will not work.

answered Aug 22, 2010 at 5:56
Sign up to request clarification or add additional context in comments.

Comments

2

If you seek to learn the actual correct usage of ipython (i.e. in interactive mode), then you should use magic commands like:

%run

and

%edit

Check help for those functions with %run?. This provides explicit examples.

See also http://ipython.org/ipython-doc/stable/interactive/tutorial.html

Thomas K
40.7k7 gold badges88 silver badges89 bronze badges
answered May 23, 2013 at 16:30

1 Comment

Also check how to reload python module stackoverflow.com/questions/437589/…

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.