all Python 3inspectfunction
inspect.ismodule()
members and modules
Checks that an object is a module (types.ModuleType), the result of an import rather than a module name as a string.
Syntax
inspect.ismodule(object) -> bool
The string 'os' is not a module; to look one up by name use sys.modules or importlib.import_module. A package is a module too: ismodule(json) is True, and ispackage() (3.14+) or the presence of __path__ tells the difference. os.path is also a module (posixpath or ntpath) even though it reads like an attribute.
Examples
import inspect, json, os
print(inspect.ismodule(os), inspect.ismodule('os')) # → True False
print(inspect.ismodule(os.path), inspect.ismodule(json)) # → True True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy