【发布时间】:2010-09-23 11:22:46
【问题描述】:
我有以下课程:
class ConstraintFailureSet(dict, Exception) :
"""
Container for constraint failures. It act as a constraint failure itself
but can contain other constraint failures that can be accessed with a dict syntax.
"""
def __init__(self, **failures) :
dict.__init__(self, failures)
Exception.__init__(self)
print isinstance(ConstraintFailureSet(), Exception)
True
raise ConstraintFailureSet()
TypeError: exceptions must be classes, instances, or strings (deprecated), not ConstraintFailureSet
什么鬼?
最糟糕的是我无法尝试 super(),因为 Exception 是基于旧的类...
编辑:是的,我尝试切换继承/初始化的顺序。
EDIT2:我在 Ubuntu8.10 上使用 CPython 2.4。你更新知道这种信息很有用;-)。不管怎样,这个小谜语已经让我的三个同事闭嘴了。你会是我今天最好的朋友...
【问题讨论】:
标签: python multiple-inheritance