我上了以下课程:
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(),因为异常是基于旧类的。。。在
编辑:而且,是的,我试图切换继承/初始化的顺序。在
编辑2:我在Ubuntu8.10上使用cpython2.4。你新知道的是这种信息是有用的;-)。不管怎样,这个小谜语让我的三个同事闭嘴了。你会是我今天最好的朋友。。。在
这怎么了?在
这是一个异常,它在名为
failures
的内部字典中包含其他异常。在你能更新你的问题,列出一些它不能做的具体事情吗?在
^{pr2}$Exception
和{我想你可以用以下方法来测试:
由于}对于如何在内部存储它们的数据有不同的想法,因此它们是不兼容的,因此您不能同时从这两者继承。在
Exception
和{在以后的Python版本中,当您试图定义类时,应该会出现一个异常:
^{pr2}$没有理由,只有解决办法
目前我还不知道原因,但我用
UserDict.UserDict
绕过了它。因为它是纯Python,所以速度比较慢,但我不认为这部分应用程序会很麻烦。在仍然对答案感兴趣;-)
相关问题 更多 >
编程相关推荐