Supposing a module named foo
is already present in the namespace, but you have made some changes in source and you want the new code to be imported, use:
reload(foo)
There is a gotcha here: if you have used from foo import bar
and you have made subsequent changes in your function bar
, then the reload will not work for you. For these cases, you might prefer too use import foo
and call foo.bar()
so that you can reload
for your changes to take effect immediately.
If you are often working in interactive session like this, then perhaps you will be interested to use ipython and add the following lines in your ipy_user_conf.py
file:
# For autoreloading of modules (%autoreload, %aimport)
import ipy_autoreload