您的位置:首页 > 其它

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

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

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

#案例
modname='test'
result='import ' + modname
exec(result)        #运行字符串
print test          #<module 'test' from 'C:\Users\Administrator\Desktop\test.pyc'>
print test.name     #python
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: