Dumping an instance

Peter Hansen peter at engcorp.com
Tue Mar 15 22:20:57 EST 2005


gf gf wrote:
> If I want to dump (for debugging) an instance and all
> of it's member attributes, what's the simplest way?
> 
> print myInstance
> 
> just gives a pointer to its location in memory

Roughly speaking, as a starting point:

from pprint import pformat
def dump(obj):
     print repr(obj)
     for name in obj.__dict__:
         val = getattr(obj, name)
         print name, '=', pformat(val)

-Peter



More information about the Python-list mailing list