Check if a parameter is a Python module?

后端 未结 6 542
野性不改
野性不改 2021-02-04 23:54

How can I (pythonically) check if a parameter is a Python module? There\'s no type like module or package.

>>> os


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 00:32

    A mix of @Greg Hewgill and @Lennart Regebro answers:

    >>> from types import ModuleType
    >>> import os
    >>> type(os) is ModuleType
    True
    

提交回复
热议问题