I wrote my own module which as the following structure:
mymodule/
├── __init__.py
├── part1.py
├── part2.py
├── part3.py
└── part4.py
To test my module I am using IPython and/or jupyter notebook (formerly Ipython Notebook). As usual I do the module import like
import mymodule
Let's say I edit some code in part2.py
and want to use the updated version of my module. First I thought just re-importing the module by import mymodule
would do the job, but it does not. To completely reload the module I have to close IPython's shell or restart jupyter's kernel and start again by importing mymodule
.
However, reffering to the docs, IPython provides an auto-update function called autoreload
which provides different modes and could be activated as follows:
%load_ext autoreload
%autoreload 1
%aimport mymodule
Using both of my snippets, I am importing mymodule
like that:
%load_ext autoreload
%autoreload 1
%aimport mymodule
import mymodule
# let's do something with the module here
However, even with activated autoreload 1
or autoreload 2
neither IPython nor jupyter are doing what I expect them to do and I still have to quit IPython's shell or restart jupyter's kernel in order to use the edited code of part2.py
which is part of mymodule
.
What am I doing wrong? It seems that I did not get the point about how this should work.
Access the Jupyter Menu You have auto-complete in Jupyter notebooks like you have in any other Jupyter environment. Simply hit the “Tab” key while writing code. This will open a menu with suggestions. Hit “Enter” to choose the suggestion.
IPython extension to reload modules before executing user code. autoreload reloads modules automatically before entering the execution of code typed at the IPython prompt.
%%writefile magic command in regular Python I just read what this does. It writes the contents of a Jupyter Cell to the specified file.
Change %autoreload 1
to %autoreload 2
like dashesy said, old version or bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With