in coffeescript:
b = (a.splice(0, len) while a.length)
demo
a = [1, 2, 3, 4, 5, 6, 7]
b = (a.splice(0, 2) while a.length)
[ [ 1, 2 ],
[ 3, 4 ],
[ 5, 6 ],
[ 7 ] ]
A
не использует super
, поэтому его нельзя использовать для кооперативного наследования. Вместо этого определите оболочку для A
, согласно Python's super()
считается супер! . (Предполагая, что вы не можете просто исправить A
в первую очередь.)
class A:
def __init__(self):
print("Started A's constructor")
print("Ended A's constructor")
# AWrapper also needs to override each method defined by A;
# those simply delegate their work to the intenral instance of A
# For example,
#
# def some_method(self, x, y):
# return self.a.some_method(x, y)
#
class AWrapper:
def __init__(self, **kwargs):
self.a = A()
super().__init__(**kwargs)
class B:
...
class C(AWrapper, B):
...
Вы можете перебрать атрибут __bases__
объекта класса, чтобы вызвать метод __init__
каждого из родительских классов:
class C(A, B):
def __init__(self):
print("Started C's constructor")
for base in self.__class__.__bases__:
base.__init__(self)
print("Ended C's constructor")
, чтобы C()
выдает: