← Go Back

How to Reload an Imported Module

Using the importlib standard module:

>>> import importlib
>>> import module # Import module for the first time.
>>> import module # Does nothing.
>>> importlib.reload(module) # Re-import module.

This is useful because Python ignores importing a module that has already been imported. Therefore, if the content of the module changed during the execution of the program or if you want to re-execute the content of the module, you must use importlib.reload().

See also our post on the import system in Python.


🐍 You might also find interesting: