Mam klasy hierarchii < - B < - C, w B, muszę trochę przetworzeniu w konstruktorze, więc wymyśliłem tego kodu z tego postu: Understanding Python super() with __init__() methodsMaksymalny błąd głębokości rekursji w Pythonie podczas wywoływania super-init.
#!/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
Jednak mam błąd runtime z maksymalnej rekursji przekroczył
File "evenmore.py", line 12, in __init__
super(self.__class__, self).__init__(v, v2)
RuntimeError: maximum recursion depth exceeded while calling a Python object
Co może być nie tak?
'Super (B, self)'. – ekhumoro
Lub jeśli potrafisz używać Pythona 3, po prostu 'super()' (Python 3 automatycznie wypełnia argumenty). – ShadowRanger