Check if a parameter is a Python module?

后端 未结 6 540
野性不改
野性不改 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:44

    Two ways,you could not import any modules:

    • type(os) is type(__builtins__)
    • str(type(os)).find('module')>-1

提交回复
热议问题