Home  >  Article  >  Backend Development  >  Python动态加载模块的3种方法

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

WBOY
WBOYOriginal
2016-06-06 11:21:111607browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn