ipython shortcut to reload modules
Jordan Greenberg
"greenbergj\" at NOSPAM wit.edu
Wed Feb 21 04:59:05 EST 2007
bernhard.voigt at 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
More information about the Python-list
mailing list