打印出python 當(dāng)前全局變量和入口參數(shù)的所有屬性
更新時(shí)間:2009年07月01日 21:53:04 作者:
打印出python 當(dāng)前全局變量和入口參數(shù)的所有屬性的實(shí)現(xiàn)代碼。
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 當(dāng)前全局變量
cndebug()#
2)打印出當(dāng)前全局變量和myobj的所有屬性
myobj={}
cndebug(myobj)
擴(kuò)展用法——當(dāng)作類方法,打印實(shí)例的成員
>>> 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 當(dāng)前全局變量
cndebug()#
2)打印出當(dāng)前全局變量和myobj的所有屬性
myobj={}
cndebug(myobj)
擴(kuò)展用法——當(dāng)作類方法,打印實(shí)例的成員
>>> class MyObj():
... debug=cndebug
...
>>> myObj1=MyObj()
>>> myObj1.debug()
相關(guān)文章
對Django項(xiàng)目中的ORM映射與模糊查詢的使用詳解
今天小編就為大家分享一篇對Django項(xiàng)目中的ORM映射與模糊查詢的使用詳解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07
python自帶緩存lru_cache用法及擴(kuò)展的使用
本篇博客將結(jié)合python官方文檔和源碼詳細(xì)講述lru_cache緩存方法是怎么實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
使用python和opencv的mask實(shí)現(xiàn)摳圖疊加
這篇文章主要介紹了使用python和opencv的mask實(shí)現(xiàn)摳圖疊加操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04
Python3.6.x中內(nèi)置函數(shù)總結(jié)及講解
今天小編就為大家分享一篇關(guān)于Python3.6.x中內(nèi)置函數(shù)總結(jié)及講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02

