1、使用系统函数__import_()
复制代码 代码如下:
stringmodule = __import__('string')
2、使用imp 模块
复制代码 代码如下:
import imp
stringmodule = imp.load_module('string',*imp.find_module('string'))
3、使用exec
复制代码 代码如下:
import_string = "import string as stringmodule"
exec import_string
最后
以上就是舒心夏天最近收集整理的关于Python动态加载模块的3种方法的全部内容,更多相关Python动态加载模块内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复