元程序 /如何取test.py中name的值

# -*- 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:UsersAdministratorDesktop	est.pyc'>
print sys.modules['test'].name  #python
原文地址:https://www.cnblogs.com/dengyg200891/p/4922339.html