super用来调用父类方法。
class Student:
def __init__(self, name, math, chinese):
self.name = name
self.math = math
self.chinese = chinese
def __getattribute__(self, item):
print("调用 __getattribute__")
return super(Student, self).__getattribute__(item)
super指向父类,这里Student的父类object,
如何理解super(Student, self).__getattribute__(item)?
调用object里面的__getattribute__,这个也不好理解?
我感觉这里的super(Student, self)没有指向它的父类,指向了它自身?
https://docs.python.org/zh-cn...
这是官方文档, 注意里面的属性
__mro__
, 你再看一下你这个类的Student.__mro__
就明白了.文档上说
在你的示例中,
Student.__mro__
的值是 (Student, object) , 所以搜索的就是 object