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
Simple usage:
1) print out the current Python global variable
Cndebug ()#
2) print all the attributes of the current global variable and myobj.
Myobj = {}
Cndebug (myobj)
Extended usage -- print instance members as class methods
>>> Class myobj ():
... DEBUG = cndebug
...
>>> Myobj1 = myobj ()
>>> Myobj1.debug ()