Python Tutorials - Herong's Tutorial Examples - v2.14, by Herong Yang
sys.modules - Listing Loaded Modules
This section provides a tutorial example on how to list modules already loaded in the memory cache, using the 'sys.modules' attribute.
If you want to know how many modules have already been loaded in the memory cache, you can use the "sys.modules" attribute, which is a "dict" object holding a name-description pair for each loaded module.
The code below shows you an example of listing loaded modules.
# import a module from a module file >>> import module_test # list all loaded modules >>> import sys >>> for m in sys.modules: ... print(f"name, description = {m}, {sys.modules[m]}") ... name, description = builtins, <module 'builtins' (built-in)> name, description = _io, <module 'io' (built-in)> name, description = time, <module 'time' (built-in)> name, description = zipimport, <module 'zipimport' (frozen)> name, description = __main__, <module '__main__' (built-in)> name, description = io, <module 'io' from '/usr/lib/python3.8/io.py'> name, description = google, <module 'google' (namespace)> ... name, description = module_test, <module 'module_test' from '/home/herong/module_test.py'> name, description = sys, <module 'sys' (built-in)>
Obviously, all of those modules were loaded by the Python system, except the last two.
Table of Contents
Variables, Operations and Expressions
Function Statement and Function Call
Iterators, Generators and List Comprehensions
"import module" - Two-Step Process
►sys.modules - Listing Loaded Modules
importlib.reload(module) - Reloading Module
"from module import member" Statement
"from module import *" Statement
__pycache__/module.version.pyc Files
Packages and Package Directories
"pathlib" - Object-Oriented Filesystem Paths
"pip" - Package Installer for Python
SciPy.org - Python Libraries for Science
pandas - Data Analysis and Manipulation
Anaconda - Python Environment Manager