How to reload "from mymodule import *" wildcard imports in Jupyter
In our previous post How to reload import in Jupyter we showed how to use reload() from importlib in order to reload a module without restarting the kernel.
reload_mymodule.py
import mymodule
# Reload .py file every time we run the cell
from importlib import reload
reload(mymodule)However, often we are using syntax like
example.py
from mymodule import *to wildcard-load everything imported from mymodule.
We can reload those wildcard imports using the same strategy by additionalling importing mymodule and then reloading using reload(mymodule) - this will also reload the wildcard import from mymodule import *!
reload_wildcard_example.py
from mymodule import *
# This line is just to facilitate reloading
import mymodule
from importlib import reload
reload(mymodule)
# Reload .py file every time we run the cell from importlib import reload reload(mymodule)Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow