用名称字符串导入模块(仅作了解即可)

# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#Python学习手册 636
#用名称字符串导入模块(仅作了解即可)



#默认情况下,exec运行当前作用域中的代码。



#案例
modname='test'
result='import ' + modname
exec(result)        #运行字符串
print test          #<module 'test' from 'C:UsersAdministratorDesktop	est.pyc'>
print test.name     #python
原文地址:https://www.cnblogs.com/dengyg200891/p/4922349.html