How to print out all the properties of python's current global variables and entry parameters
How to print out python's current global variables and entry parameters of all the properties, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
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 xrecoy 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
Simple usage:
1) print out the current global variable of python
Cndebug () #
2) print out all the properties of the current global variable and myobj
Myobj= {}
Cndebug (myobj)
Extended usage-print the members of the instance as a class method
> class MyObj ():
... Debug=cndebug
...
> > myObj1=MyObj ()
> > myObj1.debug ()
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.