Answer the question
In order to leave comments, you need to log in
What is the correct way to use super()?
Just two questions. First:
When overriding a parent class method, should super() be called first line or last?
def save(self, *args, **kwargs):
# my code here
super().save(*args, **kwargs)
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
# my code here
class Parent:
def __init__(self, *args, **kwargs):
pass
class Children(Parent):
def __init__(self, *args, **kwargs):
# some code
super(Parent, self).__init__(*args, **kwargs)
class Children(Parent):
def __init__(self, *args, **kwargs):
# some code
super(Children, self).__init__(*args, **kwargs)
Answer the question
In order to leave comments, you need to log in
super
only applies to Python2. In Python3, you can simply super().__init__(*args, **kwargs)
But if the class is still passed, then it must be the class in the method of which the call occurs.Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question