python 动态加载模块-CSDN博客

网站介绍:动态加载模块分2种情况来说明1 该模块没有调用其他模块如当前目录下有个add.py文件,文件内容如下:def add(a, b): return a + b在当前测试文件中写如下测试代码:def test_func(): module = __import__('add') func = getattr(module, "add") print(type(func)) print(func(1, 2))打印:<class '