finding origin of names

Steven Taschuk staschuk at telusplanet.net
Sat Jun 7 12:13:51 EDT 2003


Quoth Robin Becker:
  [...]
> #a.py
> v=1
> 
> #b.py
> from a import v
> 
> >>> import a, b
> >>> a.v is b.v
> 1
> >>> dir(a)
> ['__builtins__', '__doc__', '__file__', '__name__', 'v']
> >>> dir(b)
> ['__builtins__', '__doc__', '__file__', '__name__', 'v']
> >>>
> 
> 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.

-- 
Steven Taschuk                            staschuk at telusplanet.net
"Our analysis begins with two outrageous benchmarks."
  -- "Implementation strategies for continuations", Clinger et al.





More information about the Python-list mailing list