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

cool-RR cool-rr at cool-rr.com
Fri Sep 10 17:46:13 IDT 2010


Hello everyone!

I have a question:

Is there a Python module for handling Python object addresses?

When I say "object address", I mean the string that you type in Python to
access an object. For example `'life.State.step'`. Most of the time, all the
objects before the last dot will be packages/modules, but in some cases they
can be classes or other things.

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

In my Python project I often have the need to play around with object
addresses. Some tasks that I have to do:

   1. Given an object, get its address.
   2. Given an address, get the object, importing any needed modules on the
   way.
   3. Shorten an object's address by getting rid of redundant intermediate
   modules. (For example, `'life.life.State.step'` may be the official address
   of an object, but if `'life.State.step'` points at the same object, I'd want
   to use it instead because it's shorter.)
   4. Shorten an object's address by "rooting" a specified module. (For
   example,`'garlicsim_lib.simpacks.prisoner.prisoner.State.step'` may be the
   official address of an object, but I assume that the user knows where
   the prisoner package is, so I'd want to use `'prisoner.prisoner.State.step'`
   as the address.)


Is there a module/framework that handles things like that? I wrote a few
utility modules to do these things, but if someone has already written a
more mature module that does this, I'd prefer to use that.

One note: Please, don't try to show me a quick implementation of these
things. It's more complicated than it seems, there are plenty of gotchas,
and any quickly-written code will probably fail for many important cases.
These kind of tasks call for battle-tested code, and I just want to know if
such code exists or whether I will have to write it myself.


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


More information about the Python-il mailing list