[Tutor] subclasses and conflicting variables
Poor Yorick
gp@pooryorick.com
Sat Jan 11 20:35:02 2003
I understand when inheriting multiple classes, if there is an instance
identifier name conflict, the leftmost inherited class takes priority.
In the following code, instance.var1 = 'hello'. It seems to me that
this behavior could wreak havoc in multiple layers of inheritance. In
the code below, is there any way for instance to access classB.var1?
class classA:
def __init__(self):
self.var1 = 'hello'
class classB:
def __init__(self):
self.var1 = 'goodbye'
class classC(classA, classB):
def Print(self):
print self.var1
instance = classC()
instance.Print()
Poor Yorick
gp@pooryorick.com