打印出python 當前全局變量和入口參數(shù)的所有屬性
更新時間:2009年07月01日 21:53:04 作者:
打印出python 當前全局變量和入口參數(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 當前全局變量
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()
相關(guān)文章
Python常用Web框架Django、Flask與Tornado介紹
這篇文章介紹了Python常用Web框架Django、Flask與Tornado,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05淺談pytorch卷積核大小的設(shè)置對全連接神經(jīng)元的影響
今天小編就為大家分享一篇淺談pytorch卷積核大小的設(shè)置對全連接神經(jīng)元的影響,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01使用pyecharts在jupyter notebook上繪圖
這篇文章主要介紹了使用pyecharts在jupyter notebook上繪圖,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-07-07Python?xlwt工具使用詳解,生成excel欄位寬度可自適應(yīng)內(nèi)容長度
這篇文章主要介紹了Python?xlwt工具使用詳解,生成excel欄位寬度可自適應(yīng)內(nèi)容長度,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02python數(shù)據(jù)分析之將爬取的數(shù)據(jù)保存為csv格式
Python內(nèi)置了CSV模塊,可直接通過該模塊實現(xiàn)csv文件的讀寫操作,在web應(yīng)用中導出數(shù)據(jù)是比較常見操作,下面這篇文章主要給大家介紹了關(guān)于python數(shù)據(jù)分析之將爬取的數(shù)據(jù)保存為csv格式的相關(guān)資料,需要的朋友可以參考下2022-06-06