Skip to content

Tag: hash

Hashing the content of a method in Python

I am looking for a robust way to hash/serialize the content of a method in Python. Use-case: We are doing some file caching the result of a transformation function, and it would be great if it was possible to automatically refresh if transformation function has changed: I am looking for something that could potentially replace my hardcoding of a version

Why is hash of nan zero?

I would have thought would lead to frequent hash collisions. Why are they both hashed to zero? Answer This behaviour has changed in Python 3.10: Hashes of NaN values of both float type and decimal.Decimal type now depend on object identity. Formerly, they always hashed to 0 even though NaN values are not equal to one another. This caused potentially

Ignore image name while getting hash

I’m coding a program which’ll take an image for an input, check it against images in a database and output the image with the same hash However, when using hash(“imagepath”) 2 of the same images give different hashes, even when the only difference is the image’s name, which makes me believe the name is the issue Is there a way

How does Python hash itertools.count()?

I am trying to understand the underlying mechanics behind hash(itertools.count(x, y)). I am not used to looking deeply into CPython implementations, but I noticed that in itertoolsmodule.c the static PyTypeObject count_type has 0 for tp_hash. I am assuming that this means that it does not implement hash in C. So, how does it get taken care of? Is there a

Port module from Python 2.7 to 3.7

I have been struggling with this for hours. I have the following production code (parsed out for simplicity) that runs just fine in Python 2.7: The output is a string like so: But when I run this with Python3.7, I get the following error: After a quite a bit of research I understood that hmac has changed in 3.4 and

Check if files in dir are the same

I have a folder of 5000+ images in jpeg/png etc. How can I check if any of the images are the same. The images were collected through web scraping and have been sequentially renamed so I cannot compare file names. I am currently checking if the hashes are the same however this is a very long process. I am currently

Comparing Python Hashes

I want to compare a hash of my password to a hash of what the user typed in, with (str)(hashlib.md5(pw.encode(‘utf-8′)).hexdigest()). The hash of the password is b’¥_ÆMÐ1;2±*öªÝ=’. However, when I run the above code, I get b’xa5x83_xc6x85Mxd01;2xb1*xf6xaaxdd=’. For this reason, I can’t compare these two strings. I’m looking for a function that can convert b’xa5x83_xc6x85Mxd01;2xb1*xf6xaaxdd=’ to b’¥_ÆMÐ1;2±*öªÝ=’ logically (each of