Try it with the following code.
class A(object):
def __init__(self):
self.x = "whatever"
self.y= "cumbersome"
self.z = "idea"
def method1(self):
self.x = self.x.lower()
class B(A):
def __init__(self):
super(B, self).__init__()
self.a = 87
def method1(self):
super(B, self).method1()
self.y =self.y.upper()
And a list of things we changed:
- We added that
A
subclasses fromobject
to get a new-style class. (note this is only reqiured for python version 2) - We added the call to
object.__init__
inA.__init__
. Python does not call these implicitly for you, you have to do it yourself. B.__init__
now callsA.__init__
. This again need to be done by you.B.method1extended
renamed toB.method1
so that it shadowsA.method1
.B.method1
callsA.method1
before applying its own changes.