[Python-il] Is there a Python module for handling Python object addresses?

cool-RR cool-rr at cool-rr.com
Fri Sep 10 21:40:11 IDT 2010


On Fri, Sep 10, 2010 at 8:23 PM, Imri Goldberg <lorgandon at gmail.com> wrote:

> Several points:
> 1. Unless you are doing something very special (like a debugger), needing
> this seems like a bad design choice. Just my shnekel.
> 2. Although you can (in some cases for some value of some) define it,
> talking about an "official address" of an object, seems extremely
> non-pythonic.
> 3. To your actual question: you can use the gc module to get the referrers
> to a specific object. By traversing this tree structure, you can probably
> extract the information you want. Furthermore, for many objects, such as
> instances and functions, finding the definition point is not that hard
> (using the inspect module). In any case it seems to me that what you seek to
> do seek to do will be very hard to accomplish correctly, require some "deep
> magic", and IMHO, yield low returns.
>
> Cheers,
> Imri
>

Hi Imri,

I said:
"When I say "object", I mostly mean classes, modules, functions, methods,
stuff like these, which usually do not change their address."

Why would I need to use gc for it? I can get the address for almost any
object with `__module__`.

This kind of thing is used in Django settings module, (specifying strings
instead of objects themselves,) so why is it a bad design choice when I want
to do it?
Also, the pickle module in the standard library uses an object's address to
pickle some kinds of objects (classes, functions).

Anyway, I'm frustrated from getting a lot of "You're doing it wrong" answers
for this question, and I just want an answer, not explanation on why I
shouldn't do it. (My question is, "Is there a mature module for these
tasks?")


Thanks,
Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://hamakor.org.il/pipermail/python-il/attachments/20100910/009b4fc3/attachment-0001.htm 


More information about the Python-il mailing list