[Python-il] Fwd: Is there a Python module for handling Python object addresses?
aronovitch at gmail.com
Sat Sep 11 22:23:17 IDT 2010
On Sat, Sep 11, 2010 at 9:41 PM, cool-RR <cool-rr at cool-rr.com> wrote:
> Hi Rani,
> On Sat, Sep 11, 2010 at 7:56 PM, Rani Hod <rani.hod at gmail.com> wrote:
>> 3. I'm making a GUI in which the user will be able to manipulate Python
>>> functions, and I want to display the shortest name possible on the screen.
>> But this could lead to funny circumstances. Say that
>> - class Foo is defined in long_package_name/long_modulename.py
>> - long_package_name/__init__.py does
>> from long_module_name import Foo
>> - short_mod.py does
>> from long_package_name.long_module_name import Foo as Bar
>> Technically, short_mod.Bar is shorter than long_package_name.Foo; will
>> you prefer it?
> Good question, that would indeed be bad to use short_mod.Bar as a name for
> Foo. But the way I do my shortening does not allow for something like
> this to happen. (I have not mentioned this in my original message, sorry.)
> The shortening can only remove components from the address. So an address
> like a.b.c.d.e can be shortened to a.c.d.e or a.d.e but not x.y.z. So I
> think this prevents these kinds of problems from happening.
Also certainly simpler than searching all of sys.modules.
Point to consider (at the risk of being trivial): you probably want to
consider only the "exported" names (stuff in __all__ ) to avoid accidental
shortenings of names that were imported for internal use by a parent module
(and might disappear from dir() if the implementation changes).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-il