Python importlib(动态导入模块)

Posted doubtful

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python importlib(动态导入模块)相关的知识,希望对你有一定的参考价值。

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

示例:

import importlib

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

以上是关于Python importlib(动态导入模块)的主要内容,如果未能解决你的问题,请参考以下文章