Python动态加载模块的3种方法

小鱼们欢快的闹腾起来,有的甩动着尾巴,有的吐着泡泡,有的扭动着身体,互相追玩,好不热闹。春天来了!你看,融化的冰水把小溪弄醒了。 "丁粳、丁粳 ",它就像大自然的神奇歌手,唱着清脆悦耳的歌,向前奔流……

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动态加载模块的3种方法请关注haodaima.com其它相关文章!

您可能有感兴趣的文章
Python自动化运维-使用Python脚本监控华为AR路由器关键路由变化

Python自动化运维-netmiko模块设备自动发现

Python自动化运维—netmiko模块连接并配置华为交换机

Python自动化运维-利用Python-netmiko模块备份设备配置

Python3内置模块之json编码解码方法详解