Class Variable Access and Assignment
Christopher Subich
csubich.spam.block at spam.subich.block.com
Fri Nov 4 09:24:41 EST 2005
Steven D'Aprano wrote:
> On Thu, 03 Nov 2005 14:13:13 +0000, Antoon Pardon wrote:
>
>
>>Fine, we have the code:
>>
>> b.a += 2
>>
>>We found the class variable, because there is no instance variable,
>>then why is the class variable not incremented by two now?
>
>
> Because b.a += 2 expands to b.a = b.a + 2. Why would you want b.a =
> <something> to correspond to b.__class__.a = <something>?
Small correction, it expands to b.a = B.a.__class__.__iadd__(b.a,2),
assuming all relevant quantities are defined. For integers, you're
perfectly right.
More information about the Python-list
mailing list