【发布时间】:2012-09-19 09:23:23
【问题描述】:
我正在制作一个使用类的 python 程序,我希望一个类只能选择性地从另一个类继承,例如:
class X(object):
def __init__(self):
self.hello = 'hello'
class Y(object):
def __init__(self):
self.moo = 'moo'
class Z():
def __init__(self, mode):
if mode == 'Y':
# Class will now Inherit from Y
elif mode == 'X':
# Class will now Inherit for X
如何在不上其他课程的情况下做到这一点?
【问题讨论】:
-
您能否提供更多信息,说明您为什么要这样?考虑到这些赤裸裸的事实,作为一个设计决策,我觉得这有点奇怪。
标签: python