How do I unload (reload) a Python module?
To unload a Python module, you can use the del
statement to remove it from memory. For example, if you have imported a module named example_module
, you can unload it with the following code:
del example_module
Watch a video course
Python - The Practical Guide
To reload a module, you can use the importlib
library's reload
function. For example, if you have imported a module named example_module
, you can reload it with the following code:
import importlib
importlib.reload(example_module)
Please note that if the module is imported in multiple places, it will only be reloaded in the current namespace.