Class Variable Inheritance
bojo at gvea.com
Thu Dec 9 01:55:09 CET 2004
I'm sure the solution may be obvious, but this problem is driving me
mad. The following is my code:
mastervar = 
print 'called a'
print 'called b'
print 'called c'
if __name__ == '__main__':
a1 = a()
b1 = b()
c1 = c()
d1 = c() # Call C again
What I don't understand is why mastervar gets modified by each _seperate
instance_ of classes that happen to extend the base class 'a'.
Shouldn't mastervar be contained within the scope of the inheriting
classes? Why is it being treated like a global variable and being
modified by the other instances?
Brian "bojo" Jones
More information about the Python-list