Will pickle change the hash value of the variable?

@jamestwebber 's analogy to compression is very to the point I think. You think of the serialized (or compressed) binary files as “data” and then worry that the data has changed and what this may do. But it’s better to consider them as “code”. And in pickle they really are opcodes driving the deserialization and decompression. (The pickletools module also has a function to improve those opcodes - driving home the same point that different binaries can deserialize to the same object).

1 Like

I understand, now I directly detect the hash value of the data in f.read(), so that it will not be affected by pickle.

1 Like

If I want to directly calculate the sha1 value of a variable, do I need to implement the variable’s hash() function?

Hi - perhaps better to open a new thread for this question.

I ended up not using hash() because the random salt of the hash is different each time it is run.