我有一个类的层次结构A <- B <- C,在B中,我需要在构造函数中进行一些处理,因此我从这篇文章中得出了以下代码:Understanding Python super() with __init__() methods
#!/usr/bin/python
class A(object):
def __init__(self, v, v2):
self.v = v
self.v2 = v2
class B(A):
def __init__(self, v, v2):
# Do some processing
super(self.__class__, self).__init__(v, v2)
class C(B):
def hello():
print v, v2
b = B(3, 5)
print b.v
print b.v2
c = C(1,2)
print c
然而,我遇到了一个“最大递归深度超过”的运行时错误。
File "evenmore.py", line 12, in __init__
super(self.__class__, self).__init__(v, v2)
RuntimeError: maximum recursion depth exceeded while calling a Python object
可能出了什么问题?
super()
(Python 3会自动填充参数)。 - ShadowRanger