Print all attributes of the current Python global variables and entry parameters.

Source: Internet
Author: User

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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.