Answer the question
In order to leave comments, you need to log in
Return overridden method?
In general, such a situation arose.
In one of the classes (or rather in the model), some wonderful person overridden the standard method and now it does not work. In other words, I need to inherit class 3 - everything from class 2, and the desired method from class 1. How to do this?
As I understand it, this is supposedly done with the help of super...
Answer the question
In order to leave comments, you need to log in
Override the desired method yourself? For one or two methods, it may be fine, provided that you are sure that the methods of Class1 will work correctly with instances of your class.
def __methodname__(self, *args, **kwargs):
return Class1.__methodname__(self, *args, **kwargs)
Try this option here:
class X:
def __init__(self):
print("Я класс X у меня есть метод:")
self.x()
def x(self):
print("self.x")
class Y:
def __init__(self):
print("Я класс Y у меня есть метод:")
self.y()
def y(self):
print("self.y")
class Z(X,Y):
def __init__(self):
print("Я класс Z у меня есть методы:")
self.z()
self.y()
self.x()
def z(self):
print("self.z")
if __name__=="__main__":
z=Z()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question