Home »
Python
Reloading modules in Python
Learn about reloading modules in Python programming language, its syntax in various Python versions.
Submitted by IncludeHelp, on March 06, 2022
In Python, the reload() reloads a previously imported module. Reloading modules are helpful if you have edited existing modules source files using an external editor and want to use the new version of the modules without leaving the Python interpreter. The return value of reload() is the module object.
When reload() is executed – The code of module is recompiled and the module-level code re-executed, defining a new set of objects which are bound to names in the module's dictionary by reusing the loader which originally loaded the module. The init function of extension modules is not called a second time.
Syntax for Python2.x
reload(module)
Syntax for above 2.x and <=Python3.3
import imp
imp.reload(module)
Syntax for >=Python3.4
import importlib
importlib.reload(module)
Parameter (s):
- module – It should be a module which has been successfully imported.
Reference: importlib.reload(module)
ADVERTISEMENT
ADVERTISEMENT