how to test if one python module has been imported?

后端 未结 3 1622
野趣味
野趣味 2020-11-30 04:49

How to test if a module has been imported in python?

for example I need the basics:

if not has_imported(\"sys\"):
   import sys

als

3条回答
  •  臣服心动
    2020-11-30 05:15

    from sys import modules
    try:
        module = modules[module_name]
    except KeyError:
        __import__('m')   
    

    this is my solution of changing code at runtime!

提交回复
热议问题