examining python objects
rurpy at yahoo.com
rurpy at yahoo.com
Fri Nov 18 17:05:05 EST 2005
__repr__ almost always only prints a summary of it's
object, not the detailed internal structure that I want to
see. When it prints values, that are not pretty-printed,
nor are the objects that constitute the value printed
recursively.
Writing my own __repr__() is emphatically what I don't
want to do! That is no better than debugging by inserting
print statements, a technique from the 1980's.
I am surprised (err, astounded actually) that a basic
tool like this isn't available. Besides debugging, I would
think it would be very helpful to people leaning python.
Perhaps one of the Python IDEs contains something
like this I could extract from it but I was hoping to shortcut
what will be a time consuming search.
Ben Finney wrote:
> 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