finding origin of names
robin at jessikat.fsnet.co.uk
Sat Jun 7 19:20:34 CEST 2003
In article <mailman.1055004899.24832.python-list at python.org>, Steven
Taschuk <staschuk at telusplanet.net> writes
>> do I have to inspect the code to determine that module a defines v?
>It's not clear to me what this question means.
>First, a.v and b.v are distinct names, that is, they can be
>rebound independently; so surely you have to ask separately
>whether a given module defines a.v and whether it defines b.v.
>Second, I'm not sure what "defines" means here. Do you just want
>the location of the last assignment statement (or def statement,
>etc.) which bound that name? (I don't think that information is
>easily available.) And if so, why do you care? It's all the same
>object regardless of which code bound it to the name you're using
>to refer to it.
OK I'm being stupid we're importing these things for their value. So I
really mean to find the original use of the value.
For the value 1 it's not that obvious, but suppose I create
red = Color(1,0,0)
from a import red
then in derived modules I have a choice to import red from either a or
b. Since the b name is imported from a, we can regard the b name as
derivative for these kinds of constant and therefore prefer to import
from a (the source of the definition).
More information about the Python-list