说我有A,B和C类。它们每个都有10多个实例属性。我将创建继承类A,B和C的类D。在类D中组织大量实例属性的最佳实践是什么?任何想法将不胜感激。谢谢!
class A:
def __init__(self, a, b, c, d,...):
self.a = a
self.b = b
self.c = c
self.d = d
...
class B:
def __init__(self, e, f, g, h,...):
self.e = e
self.f = f
self.g = g
self.h = h
...
class C:
def __init__(self, i, j, k, l,...):
self.i = i
self.j = j
self.k = k
self.l = l
...
class D(A, B, C):
def __init__(self, a, b, c, d, e, f, g, h, i, j, k, l, ..., z):
A.__init__(self, a, b, c, d,...)
B.__init__(self, e, f, g, h,...)
C.__init__(self, i, j, k, l,...)
self.z = z
答案 0 :(得分:0)
我认为列表解压操作符可能对您有帮助—
manyargs = [a, b, ...]
class D(A, B, C):
def __init__(self, *manyargs):
...
此外,可能可能对阅读super()有所帮助