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

yipeiwu_com6年前Python基础

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中矩阵创建和矩阵运算方法

Python中矩阵创建和矩阵运算方法

矩阵创建 1、from numpyimport *; a1=array([1,2,3]) a2=mat(a1) 矩阵与方块列表的区别如下: 2、data2=mat(ones((2,4)...

在Python中使用dict和set方法的教程

在Python中使用dict和set方法的教程

dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度。 举个例子,假设要...

pyqt5的QWebEngineView 使用模板的方法

说明1:关于QWebEngineView pyqt5 已经抛弃 QtWebKit和QtWebKitWidgets,而使用最新的QtWebEngineWidgets。 QtWebEng...

python操作gitlab API过程解析

这篇文章主要介绍了python操作gitlab API过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 使用 python-gi...

python实现读取大文件并逐行写入另外一个文件

<pre name="code" class="python">creazy.txt文件有4G,逐行读取其内容并写入monday.txt文件里。 def crea...