Python動態(tài)加載模塊的3種方法
更新時間:2014年11月22日 09:53:42 投稿:junjie
這篇文章主要介紹了Python 動態(tài)加載模塊的3種方法,本文分別使用使用系統(tǒng)函數(shù)__import_()、使用imp 模塊、使用exec三種方法實現(xiàn),需要的朋友可以參考下
1、使用系統(tǒng)函數(shù)__import_()
復(fù)制代碼 代碼如下:
stringmodule = __import__('string')
2、使用imp 模塊
復(fù)制代碼 代碼如下:
import imp
stringmodule = imp.load_module('string',*imp.find_module('string'))
3、使用exec
復(fù)制代碼 代碼如下:
import_string = "import string as stringmodule"
exec import_string
相關(guān)文章
python列表插入append(), extend(), insert()用法詳解
在本篇文章里小編給大家整理了關(guān)于python列表插入append(), extend(), insert()用法以及相關(guān)知識點,有需要的朋友們參考下。2019-09-09python射線法判斷一個點在圖形區(qū)域內(nèi)外
這篇文章主要為大家詳細(xì)介紹了python射線法判斷一個點在圖形區(qū)域內(nèi)外,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-06-06