easy way to dump a class instance?
bruno at modulix
onurb at xiludom.gro
Fri May 5 13:43:02 EDT 2006
Mark Harrison wrote:
> Is there a way to automatically print all the instance
> data in a class? This is for debugging, I would like
> to do something like dump(self) to snapshot the state
> of the object.
def dump(obj):
buf = ['%r %s :' % (obj, str(obj)]
for name in dir(obj):
attr = getattr(obj, name)
if not callable(attr):
buf.append["- %s : %s" % (name, str(attr))]
return '\n'.join(buf)
Not tested...
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list