471,049 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

ipython shortcut to reload modules

Hey!

I'm using ipython as my python shell and often run scripts with the
magic command %run:

In [1]: %run script.py

If modules are loaded within the script these are not reloaded when I
rerun the script. Hence, when I changed some of the modules loaded, I
have to call

In [2]: reload(module1)
Out [2]: <module 'module1' from ....
In [3]: reload(module2)
Out [3]: <module 'module2' from ...
In [4]: %run script.py

Is there a shortshut to reload the modules automatically before
rerunning the script?

In case of names imported from modules into the shell environment I
have to reload and re-import in order to have the changes available:

In [5]: from module1 import *
In [6]: reload(module1)
In [7]: from module1 import *

Is there a shortcut to force a reload of loaded modules and re-
defining the names loaded with from....import...?

Thanks! Bernhard

Feb 19 '07 #1
1 13246
be************@gmail.com wrote:
Hey!

I'm using ipython as my python shell and often run scripts with the
magic command %run:

In [1]: %run script.py

If modules are loaded within the script these are not reloaded when I
rerun the script. Hence, when I changed some of the modules loaded, I
have to call

In [2]: reload(module1)
Out [2]: <module 'module1' from ....
In [3]: reload(module2)
Out [3]: <module 'module2' from ...
In [4]: %run script.py

Is there a shortshut to reload the modules automatically before
rerunning the script?
No. But if you're including them in the script, they won't be reloaded
because they're already present in the namespace. If you do %reset
before your %run, it'll clear up the namespace, so your script's import
should work. Downside: its effectively the same as quitting out of
ipython, and restarting it. Other then that, I don't think you have much
choice.
Oh, if you use the %edit command to edit these files, it should reload
them when you're done editing.
-Jordan
Feb 21 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

66 posts views Thread by Ellinghaus, Lance | last post: by
4 posts views Thread by David MacQuigg | last post: by
1 post views Thread by Ismael Herrera | last post: by
3 posts views Thread by Dave Merrill | last post: by
4 posts views Thread by Lonnie Princehouse | last post: by
reply views Thread by Fernando Perez | last post: by
2 posts views Thread by Daniel Mark | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.