Computer >> Computer tutorials >  >> Programming >> Python

What does reload() function do in Python?


The function reload(moduleName) reloads a previously loaded module (assuming you loaded it with the syntax "import moduleName". It is intended for conversational use, where you have edited the source file for a module and want to test it without leaving Python and starting it again. For example,

>>> import mymodule
>>> # Edited mymodule and want to reload it in this script
>>> reload(mymodule)

Note that the moduleName is the actual name of the module, not a string containing its name. In Python 3, reload was moved from builtins to imp. So to use reload in Python 3, you'd have to write imp.reload(moduleName) and not just reload(moduleName).