Quote:
> Heya,
> How can i overload hash() to take a custom class and return a custom
> computed hash value?
> i note that hash(object) works for string and likely other built in
types...
> print hash ("Hello")
> i would like to use this form of the function for say
> temp = MyClass ()
> print hash (temp)
Define a hash method for your class. For example:
class Hasher:
def __hash__(self):
return 58
h = Hasher()
print hash(h)
prints 58.