Check if a parameter is a Python module?

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

    Flatten the module to a string and check if it starts with '

    import matplotlib
    foobarbaz = "some string"
    print(str(matplotlib).startswith("

    Drawback being this could collide with a python string that starts with the text ' You could try to classify it more strongly with a regex.

提交回复
热议问题