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 to resume…’) del x,y,o 简单用法: 1)打印出python 当前全局变量 cndebug()# 2)打印出当前全局变量和myobj的所有属性 myobj={} cndebug(myobj) 扩展用法——当作类方法,打印实例的成员 >>> class myobj(): … debug=cndebug … >>> myobj1=myobj() >>> myobj1.debug()