[Tutor] super constructor usage
Rafael Knuth
rafael.knuth at gmail.com
Wed Mar 29 10:33:20 EDT 2017
I am trying to wrap my head around the super constructor. Simple example:
class A:
def __init__(self):
print("world")
class B(A):
def __init__(self):
print("hello")
super(B, self).__init__()
B()
Then I changed the parent class A like this, as I wanted to test how
the code would look like if I passed arguments:
class A:
def __init__(self, message):
self.message = message
print(message)
I then modified the child class B like this:
class B(A):
def __init__(self, message):
print("This is the message from your parent class A:")
super(B, self).__init__(message)
B("BlaBla")
That works, however I am not sure about what exactly happens inside the code.
What I am concerned about is whether the argument is being actually
inherited from the parent class A or does B overwrite the argument.
Can anyone advise what the correct solution would be (in case mine is wrong).
Thank you.
More information about the Tutor
mailing list