examining python objects

rurpy at yahoo.com rurpy at yahoo.com
Fri Nov 18 22:05:43 EST 2005


"Chris Mellon" <arkanes at gmail.com> wrote:
On 18 Nov 2005 14:05:05 -0800, rurpy at yahoo.com <rurpy at yahoo.com> wrote:
> -- snip --
> > 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

Yes and I often resort to it when I have no other choice.
But it is often faster and more efficient to step through
a section of problem code in pdb and look at variables.
(And no I don't want to use a hevyweight or gui based ide.)

> > 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__
> or __slots__.

Well, my reason for posting is that i've spent a couple days
already trying to roll my own and it is not so easy.  For one
thing, my knowlage about all of the nitty gritty of the internals
of objects is limited.  A big part of my wanting this is to help
me understand objects better.  Does __dict__ and __slots__
give you all the attributes of an object?  I thought new-style
objects didn't even have a __dict__.  I notice dir() does not
list __dict__ as an attribute, even though it is one.  You can
see my understanding of these things is rather limited right
now (due in no small part to Python's shitty docs.)

While doing this is a educational, I am (supposed to be) working
on something else I need to finish.  I think it is more efficient to
learn by looking at objects with a pre-written tool, then to spend
a week or more trying to write it myself.  And also, I also don't
like taking days to duplicate something I'm sure has already been
done numerous times.

> > 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
> find useful.
>-- snip --

I'll look for this but I'd rather find something I didn't have to hack.
What a bummer, maybe I should be posting this to the "reinventing
the wheel" thread.  :-(




More information about the Python-list mailing list