Non-symmetric access

Craig Lawson (claw@rahul.net)
Wed, 17 Aug 1994 22:43:46 GMT

Here's a case where variable reference and variable assignments are
non-symmetric:

class a: # give a unique integer ID to all instances
i = 1 # class variable
def __init__(self):
self.j = self.i # instance variable <-- class variable
self.i = self.i + 1 # modify class variable (?)

Does the last statement modify the class variable or not?
No. Here's a sample run:

>>> a1 = a() --> <instance...>
>>> a2 = a() --> <instance...>
>>> a1.__dict__ --> {j:1, i:2}
>>> a2.__dict__ --> {j:1, i:2}
>>> a.i --> 1

Is this a good thing, or bad?

-- 
Craig Lawson
claw@rahul.net