object data member dumper?

Steve Holden steve at holdenweb.com
Wed Nov 8 03:40:18 CET 2006


tom arnall wrote:
> Steve Holden wrote:
> 
> 
>>Bruno Desthuilliers wrote:
>>
>>>tom arnall a écrit :
>>>
>>>
>>>>does anyone know of a utility to do a recursive dump of object data
>>>>members?
>>>>
>>>
>>>
>>>What are "object data members" ? (hint: in Python, everything is an
>>>object - even functions and methods).
>>>
>>>What is your real use case ?
>>
>>Basically it sounds like the OP wants to see the attribute values for an
>>object (and those objects' attribute values, ...). Presumably the
>>recursive descent could be stopped at the built-in types.
> 
> 
> Yes, exactly. But what is 'OP'?
> 
"original poster" (you)
> 
>>I'm not familiar with any such thing. 
> 
> 
> I'm amazed that there is no way to easily look at the fundamental data
> structures of a python program. I'm new to python - is there something I
> don't know about the territory in this regard?
> 
Well, new enough to be unaware that Python normally doesn't need such 
drastic measures for debugging. When you are building complex data 
structures such a form of output could get big really quickly. I've 
never come across anything like it in any other language that I have used.

The most that's usually required is a __repr__() method that dumps the 
values of necessary data attributes.
> 
>>The code of the standard library's
>>pprint module might be a good place to start 
> 
> 
> I played around with this but it seems more targetted to looking at python
> objects as opposed to user-defined.
> 
It is, but it could be used as a basis for something more to your liking.
> 
>>(and the suggested
>>functionality might make a nice addition if we could work out exactly
>>what the requirement was).
> 
> 
> I would be glad if people would comment on my example as a step in this
> direction.
> 
I'd suggest you instead consider a mixin object that will add recursive 
data dump functionality to any such classes you require.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list