使用 Python importlib(动态导入模块) 可以将字符串型的模块名导入

示例:

import importlib

module = 'module name'                      # 字符串型模块名
test = importlib.import_module(module)      # 导入模块
print(test.Class().attr)                    # 打印 Class 类的 attr 属性

相关文章:

  • 2022-02-27
  • 2021-12-06
  • 2021-07-30
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2021-06-13
  • 2021-06-19
  • 2021-05-21
  • 2021-10-06
  • 2022-01-21
相关资源
相似解决方案