ADVERTISEMENT
ADVERTISEMENT

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


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.