如何在 Python 中检查给定对象是否为模块?
这是我尝试过的:
>>> import sys
>>> sys.modules["sys"].__class__
<class 'module'>
>>> isinstance(sys.modules["sys"], module)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'module' is not defined
>>> sys.modules["sys"].__class__.__module__
'builtins'
>>> import builtins
>>> builtins.module
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'module'