打印出python 当前全局变量和入口参数的所有属性
def cndebug(obj=False):
"""
Author : Nemon
Update : 2009.7.1
TO use : cndebug(obj) or cndebug() or MyObject.debug=cndebug
License: GPL
"""
print('='*80)
print('='*30 + ' GLOBAL VARIABLES ' +'='*30)
print('='*80)
g=globals()
for x,y in g.iteritems():
if x[:1]!='_':
print ( x + ' := '+ str(type(y)))
print ( y)
print ( '')
if obj:
print('='*80)
print('='*30 + ' LOCAL VARIABLES ' +'='*30)
print('='*80)
for o in dir(obj):
#if o[:1]!='_':
print (o + ' := ' + str(type(getattr(obj,o))))
print ( getattr(obj,o))
print ( '')
print('='*80)
o=raw_input('PRESS <ENTER> TO RESUME...')
del x,y,o
简单用法:
1)打印出python 当前全局变量
cndebug()#
2)打印出当前全局变量和myobj的所有属性
myobj={}
cndebug(myobj)
扩展用法――当作类方法,打印实例的成员
>>> class MyObj():
... debug=cndebug
...
>>> myObj1=MyObj()
>>> myObj1.debug()
"""
Author : Nemon
Update : 2009.7.1
TO use : cndebug(obj) or cndebug() or MyObject.debug=cndebug
License: GPL
"""
print('='*80)
print('='*30 + ' GLOBAL VARIABLES ' +'='*30)
print('='*80)
g=globals()
for x,y in g.iteritems():
if x[:1]!='_':
print ( x + ' := '+ str(type(y)))
print ( y)
print ( '')
if obj:
print('='*80)
print('='*30 + ' LOCAL VARIABLES ' +'='*30)
print('='*80)
for o in dir(obj):
#if o[:1]!='_':
print (o + ' := ' + str(type(getattr(obj,o))))
print ( getattr(obj,o))
print ( '')
print('='*80)
o=raw_input('PRESS <ENTER> TO RESUME...')
del x,y,o
简单用法:
1)打印出python 当前全局变量
cndebug()#
2)打印出当前全局变量和myobj的所有属性
myobj={}
cndebug(myobj)
扩展用法――当作类方法,打印实例的成员
>>> class MyObj():
... debug=cndebug
...
>>> myObj1=MyObj()
>>> myObj1.debug()
相关推荐
lhtzbj 2020-11-17
PythonMaker 2020-07-05
liusarazhang 2020-06-28
Leewoxinyiran 2020-03-06
wyqwilliam 2019-12-13
宿舍 2019-11-11
georgeandgeorge 2019-11-01
繁华落尽梦一场 2019-04-30
xhgWanderingsoul 2019-04-26
jling 2019-07-01
pengkunstone 2019-07-01
zhichengangle 2013-01-21
LiuRuilun 2018-09-23
zhichengangle 2018-05-12
CodeAsWind 2018-05-14
PythonMaker 2018-04-20
huavhuahua 2018-09-03
hbupig 2018-12-13