[Python-Dev] Namespaces
Martin v. Loewis
martin@v.loewis.de
06 Apr 2002 09:00:03 +0200
Aahz <aahz@pythoncraft.com> writes:
> Rebinding a <foo> does not affect the originally bound object
> (unless the originally bound object's reference count goes to zero).
>
> Any ideas about what to call <foo>? (Calling it a binding sounds a
> little too self-referential.)
That is a "name".
> > Furthermore, some attributes live in multiple namespaces. Given
> >
> > obj.name
> >
> > what namespace is considered to find the name? NOT the namespace of
> > obj, alone - Python also considers the namespace of obj's class (if
> > obj is an instance), of the base classes, etc. OTOH,
> >
> > obj.name = None
> >
> > modifies the namespace of obj (unless name is a computed attribute).
I'm saying that name lookup considers multiple namespaces in some
cases:
>>> class X:
... name = 1
...
>>> x.name
1
>>> x.__dict__.has_key("name")
0
So saying that x.name yields the value from searching the name in the
namespace of x is wrong.
Regards,
Martin