Attribute reference design
gherron at islandtraining.com
Wed Jul 2 01:17:21 CEST 2008
> On Jul 1, 11:24 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>> chamalulu schrieb:
>>> I think I'm aware of how attribute access is resolved in python. When
>>> referencing a class instance attribute which is not defined in the
>>> scope of the instance, Python looks for a class attribute with the
>>> same name. (For assignment or deletion this is not the case,
>>> I've been trying to understand why? What is the reason behind, or
>>> practical purpose of, this design decision? Anyone, please enlighten
>> How else would you resolve methods which are of course defined on the
>> class but invoked through the instance?
> Yes, of course... You're right.
> Didn't think of that.
> Thank you. I'll go stand in the corner. :)
No need. Also, you can define a class attribute (C++ might call it a
static attribute) and access it transparently through an instance.
aClassAttribute = 123
def __init__(self, ...):
c = C()
... do something with c.aClassAttribute ...
> I think I haven't got this bound/unbound stuff through my head yet. If
> I dir() a class instance I see the methods right there. Are they not
> bound to the class instance at instanciation (and as such be
> attributes of the class instance)?
More information about the Python-list