Class Variable Access and Assignment
venk
venkatasubramanian at gmail.com
Thu Nov 3 09:28:41 EST 2005
Again (blink) quoting from the docs "
For targets which are attribute references, the initial value is
retrieved with a getattr() and the result is assigned with a setattr().
Notice that the two methods do not necessarily refer to the same
variable. When getattr() refers to a class variable, setattr() still
writes to an instance variable. For example:
class A:
x = 3 # class variable
a = A()
a.x += 1 # writes a.x as 4 leaving A.x as 3
"
I felt a wee bit clear after going thru the doc... attribute
referencing is not the same as searching the variable in the enclosing
scopes.... But, i still feel the inconsistency...
More information about the Python-list
mailing list