class A(object):
def __init__(self):
self.v1 = 1
self.v2 = 2
class B(A):
def __init__(self):
super(B, self).__init__()
self.v2 = 4
self.v3 = 3
c = B()
print c.v3, c.v2, c.v1
>C:\Python25\pythonw -u "testClass.py"
3 4 1
>Exit code: 0
>>> class A(object):
… def __init__(self):
… self.v1 = 1
… self.v2 = 2
…
>>> class B(A):
… def __init__(self):
… super(B, self).__init__()
… self.v2 = 4
… self.v3 = 3
…
>>> c = B()
>>> c.v3
3
>>> c.v2
4
>>> c.v1
1
>>>
I can see why this is happening - B's init is overwriting A's completely. Is there a convenient way around this, so that I can leave v1 untouched in B while overwriting v2 and adding v3?
EDIT: Typo :(