Print out all the attributes of the python current global variable and entry parameter

  • 2020-04-02 09:19:22
  • OfStack

Def cndebug (obj = False) :
"" "
Author: Nemon
Update: 2009.7.1
TO use: cndebug(obj) or cndebug() or myobject.debug =cndebug
License: the GPL
"" "
Print (' = '* 80)
Print ('='*30 +' GLOBAL VARIABLES '+'='*30)
Print (' = '* 80)
G = globals ()
For x, y in g.i teritems () :
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 out all the properties of the current global variable and myobj

Myobj = {}

Cndebug (myobj)

Extended usage - prints the members of the instance as class methods

> > > The class MyObj () :
. The debug = cndebug
.
> > > MyObj1 = MyObj ()
> > > MyObj1. Debug ()

Related articles: