python - Is there a built-in function to print all the current properties and values of an object? -


so i'm looking here php's print_r function. can debug scripts seeing what's state of object in question.

you mixing 2 different things.

use dir(), vars() or inspect module interested in (i use __builtins__ example; can use object instead).

>>> l = dir(__builtins__) >>> d = __builtins__.__dict__ 

print dictionary fancy like:

>>> print l ['arithmeticerror', 'assertionerror', 'attributeerror',... 

or

>>> pprint import pprint >>> pprint(l) ['arithmeticerror',  'assertionerror',  'attributeerror',  'baseexception',  'deprecationwarning', ...  >>> pprint(d, indent=2) { 'arithmeticerror': <type 'exceptions.arithmeticerror'>,   'assertionerror': <type 'exceptions.assertionerror'>,   'attributeerror': <type 'exceptions.attributeerror'>, ...   '_': [ 'arithmeticerror',          'assertionerror',          'attributeerror',          'baseexception',          'deprecationwarning', ... 

pretty printing available in interactive debugger command:

(pdb) pp vars() {'__builtins__': {'arithmeticerror': <type 'exceptions.arithmeticerror'>,                   'assertionerror': <type 'exceptions.assertionerror'>,                   'attributeerror': <type 'exceptions.attributeerror'>,                   'baseexception': <type 'exceptions.baseexception'>,                   'buffererror': <type 'exceptions.buffererror'>,                   ...                   'zip': <built-in function zip>},  '__file__': 'pass.py',  '__name__': '__main__'} 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -