我有一个关于Python的hash(self)函数的问题。你知道吗
因此,在我的方法中,我有以下代码片段
def __init__(self, upper1, lower1, upper2, lower2):
self.phase = 1
self.gammas = frozenset()
self.gammabars = frozenset()
def __hash__(self):
if self.gammas:
return hash(self.gammas)
elif self.gammabars:
return hash(self.gammabars)
所以我想说:
如果自我介绍.gammas不为空,则返回自我介绍.gammas或者自我。gammabars等等
但如果我现在开始我的程序,我会得到:
TypeError: __hash__ method should return an integer
你知道怎么解决吗?你知道吗
使用元组方法的哈希:
调用
hash(instance)
时,您的self.gammas
或self.gammabars
都不能是True
。您可以尝试添加else案例:或者调试代码以确认
self.gammas
和self.gammabars
值。你知道吗相关问题 更多 >
编程相关推荐