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

WBOY
Release: 2016-06-06 11:21:11
Original
1653 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template