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

cool-RR cool-rr at cool-rr.com
Fri Sep 10 23:11:43 IDT 2010

On Fri, Sep 10, 2010 at 9:26 PM, Shai Berger <shai at platonix.com> wrote:

> On Friday 10 September 2010, cool-RR wrote:
> > Why would I need to use gc for it? I can get the address for almost any
> > object with `__module__`.
> >
> "Almost" indeed. Expect problems with naive decorators (those who wrap
> functions without using functools.wraps or doing the equivalent), in
> particular.
> > 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?
> It's fine when you go from names to objects (as Django does). It's
> suspicious
> when you try to go from objects to names, because there is (in general) no
> unique or even preferred name for any objects; and functions, methods and
> classes are just like any other object in that respect. Imri's mention of a
> debugger makes me think that is what he was referring to.

I think that the name shown in `repr` is the preferred name. That's the name
that I take.

> > 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?")
> >
> Your frustration notwithstanding, this is a public list and people will
> express their opinions and not just what you want to hear.
> I am not aware of a mature module for the tasks you specified, and -- for
> the
> reasons mentioned above -- believe the existence of one is unlikely.
> Hope this helps,
>         Shai.

Thanks Shai. Unless anyone knows of something like that, I will probably
create one. (I already have code that does most of it, I just need to
organize it, document it, write tests etc.)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://hamakor.org.il/pipermail/python-il/attachments/20100910/b5d6a88b/attachment.htm 

More information about the Python-il mailing list