元程序 /如何取test.py中name的值
2015-10-30 08:54
337 查看
# -*- coding: utf-8 -*- #python 27 #xiaodeng #Python学习手册 633 #模块是对象:元程序 #因为模块通过内置属性显示了他们的大多数特性,因此很容易编写程序来管理其他程序,我们称这类管理程序为元程序。我们在其他系统之上工作 #元程序 #编写一个程序,能够操纵改变其他程序,这叫元程序。 #test模块 #test.py # -*- coding: utf-8 -*- #python 27 #xiaodeng _x='xiaodeng' name='python' def func(): print 'def' #查找name的属性 import test,sys print test.name #python print test.__dict__['name'] #python,可以理解为__dict__返回的是一个dict形式,而__dict__['name']就是取dict的值(value) print getattr(test,'name') #python 比较顶层的概念和用法 print sys.modules['test']#<module 'test' from 'C:\Users\Administrator\Desktop\test.pyc'> print sys.modules['test'].name #python
相关文章推荐
- 第九周 项目3-稀疏矩阵的三元组表示的实现及应用
- netbeans打开UTF文件,提示无法使用
- java制作广告图片自动轮播控件
- 第六周项目2——建立链栈算法库
- Notepad 自动补全的插件 安装 (包括html,JavaScript)
- 第九周-项目1-猴子选大王
- 第九周 项目二(2) 对称矩阵压缩存储的实现与应用
- 听我说说我的博客: 月访问量过万的个人IT博客的技术史
- 第九周项目2-对称矩阵压缩存储的实现与应用(2)
- 在MapReduce中利用MultipleOutputs输出多个文件
- Android框架集合
- mysql日期函数互转
- 一些技巧吧!Unity Tips(日常使用)
- Android中可以做的两件坏事---破解锁屏密码和获取Wifi密码
- 第9周、项目2(3)—对称矩阵的压缩存储的实现与运用
- Number Sequence
- EA Sports reveal price range and transfer market changes
- 第七周--数据结构--插入正数, 摒弃负数。
- csrf laravel
- 第九周 项目一-猴子选大王