
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How do I unload (reload) a Python module?
The function reload(moduleName) reloads a previously loaded module (assuming you loaded it with the syntax "importmoduleName" without exiting the script. 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 mymoduleand 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. The python docs state following about reload function:
Python modules’ code 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. The init function of extension modules is not called a second time. The names in the module namespace are updated to point to any new or changed objects. Other references to the old objects (such as names external to the module) are not rebound to refer to the new objects and must be updated in each namespace where they occur if that is desired.
- Related Articles
- How do I find the location of Python module sources?
- How do I find the current module name in Python?
- How do I disable log messages from the Requests Python module?
- What does reload() function do in Python?
- How I can dynamically import Python module?
- How I can check a Python module version at runtime?
- How I can install unidecode python module on Linux?
- How do I calculate the date six months from the current date using the datetime Python module?
- How do I create a Python namespace?
- How to write a python module?
- How to install a Python Module?
- How to develop a Python Module?
- How do I copy a file in python?
- How do I look inside a Python object?
- How do I delete a file in Python?
