按照教程写类继承的代码,但是一直结果报错,代码如下 比较简单
class father(object):
def __init__(self, attribute_value1, attribute_value2):
self.attribute1 = attribute_value1
self.attribute2 = attribute_value2
def __str__(self):
return "\"父类father\""
def __del__(self):
return "已删除%s" % (father.__str__(self))
def testFunction(self, parameter1, parameter2):
return f"{father.__str__(self)}的属性值是{self.attribute1}和{self.attribute2},参数是{parameter1}和{parameter2}"
class son(father):
def __init__(self):
super(father, self).__init__()
self.attribute1, self.attribute2 = "1", 2
def __str__(self):
return "子类son"
def __del__(self):
return "已删除%s" % (son.__str__(self))
def old_method(self):
super(father, self).__init__()
return super(father, self).testFunction()
result = son()
print(result.attribute2, result.attribute1)
print(result.old_method())
然后运行下来是报错,就是这个错误"AttributeError: 'super' object has no attribute '"
我检查了好几遍缩进的情况,也在网上查了,没找到解决办法
请问有没有办法能解决啊 感谢各位