Dict when defining not returning multi value key error
Marko Rauhamaa
marko at pacujo.net
Sat Aug 2 03:06:02 EDT 2014
Marko Rauhamaa <marko at pacujo.net>:
> Important systems absolutely rely on the fact that the hashes can be
> used for identification. They are not just checksums. They are not
> double-checked with bit-to-bit comparisons of the actual data.
And in fact, you can use the principle in Python:
class Thingy:
def __init__(self, ...):
...
self.stronghash = self.compute_strong_hash()
self.hash = struct.unpack("Q", self.stronghash[:8])[0]
def __hash__(self):
return self.hash
def __eq__(self, other):
try:
return self.stronghash == other.stronghash
except AttributeError:
return False
Marko
More information about the Python-list
mailing list