根据我的理解,该函数super应该允许嵌套在另一个中的Class访问其父级的'self'.我可能错了,但这里有一个我想要实现的简单例子:
class Test:
def __init__(self):
self.message = "Hello World"
class Print:
def __init__(self):
print super(Test, self).message
this = Test()
this.Print()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home1/users/joe.borg/<ipython-input-3-3eb5db70be43> in <module>()
----> 1 this.Print()
/home1/users/joe.borg/<ipython-input-1-cee67a2914c3> in __init__(self)
4 class Print:
5 def __init__(self):
----> 6 print super(Test, self).message
7
TypeError: must be type, not classobj
Run Code Online (Sandbox Code Playgroud)