Tuesday, September 04, 2012

Print all object attributes in python

In case of lack of documentation for some API you may need, for example, list of attributes for some object. You can do that using:


from pprint import pprint
pprint (vars(myobject))


or...



pprint (dir(obj))


or....


import inspect
inspect.getmembers(obj, predicate=inspect.ismethod)


No comments: