examining python objects

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Nov 18 16:24:51 EST 2005


rurpy at yahoo.com wrote:
> Is there a function/class/module/whatever I can use to look at
> objects?

The repr() function is what you want.

> I want something that will print the object's value (if any) in
> pretty-printed form, and list all it's attributes and their values.
> And do all that recursively.

The repr() function returns what the object's __repr__ method returns.
You'll notice that the builtin container types (string, set, list,
dict, ...) will show the values of their referred objects also.

Define the __repr__ method on your classes so that they show whatever
information you think is useful for debugging.

-- 
 \       "If you go flying back through time and you see somebody else |
  `\   flying forward into the future, it's probably best to avoid eye |
_o__)                                        contact."  -- Jack Handey |
Ben Finney



More information about the Python-list mailing list