Amelio Vazquez-Reina
Amelio Vazquez-Reina

Reputation: 96264

IPython 0.13: autoreloading modules every time I enter a command?

Say I have a script that imports various modules in Python.

import my_module
from some_other_module import foo
...

I then run this script from IPython.

Say I make changes to the function bar in my_module and foo in some_other_module.

Say that I now want to interactively call either my_module.bar() or foo() from my IPython session.

  1. Is there a way to have IPython automatically reload every loaded module when I invoke a command before executing the command?
  2. If not automatically, how can I reload every loaded module manually in IPython without having to explicitly name the module?
  3. Finally, is there a way to set up my IPython session in my ipython_config.py (startup file) so that it supports this functionality off-the-shelf?

Upvotes: 0

Views: 311

Answers (1)

Matt
Matt

Reputation: 27843

I would suggest a %load_ext autoreload followed by a %autoreload? to see how to use it.

You can also have a look at InteractiveShellApp.extensions and InteractiveShellApp.extra_extension configuration options for extension at startup.

Finally, you can also add a .py file in your IPython profile dir ($ ipython locate to get it), put it in the startup subfolder, it will be executed at startup time.

There is a restriction though, C modules cannot be reloaded.

Upvotes: 3

Related Questions