examining python objects
arkanes at gmail.com
Fri Nov 18 23:42:23 CET 2005
On 18 Nov 2005 14:05:05 -0800, rurpy at yahoo.com <rurpy at yahoo.com> wrote:
> __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
> 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.
It's still a good idea, though
> 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.
All of this functionality is intrinsically available within Python -
it's a dynamic language and you can easily inspect an object directly
to see what it looks like. Try (pretty) printing the objects __dict__
> 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.
wxPython includes a graphical shell & namespace browser which you may
> 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