multiple inheritance in python diamond problem code example
Example: python multiple inheritance diamond problem
class Value():
def __init__(self, value):
self.value = value
print("value")
def get_value(self):
return self.value
class Measure(Value):
def __init__(self, unit, *args, **kwargs):
print ("measure")
self.unit = unit
super().__init__(*args, **kwargs)
def get_value(self):
value = super().get_value()
return f"{value} {self.unit}"
class Integer(Value):
def __init__(self, *args, **kwargs):
print("integer")
super().__init__(*args, **kwargs)
def get_value(self):
value = super().get_value()
return int(value)
class MeasuredInteger(Measure, Integer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
mt = MetricInteger("km", 7.3)
mt.get_value()