I'm trying to make a function that can take an argument and return a unique, short expression of that data.
A hash.
There's a whole hashlib
package for doing this, but hashlib
only takes strings. I want to easily hash anything: lists
, functions
, classes
, anything.
How can I either convert anything into a unique string representation so I can hash it, or better yet, directly hash anything?
I thought you might be able to get the bytes()
representation of an object but this needs special encodings for whatever it's given, and whatnot. so I'm not sure if there's a solution there.
hash_any(thing):
# convert thing to a string of it's unique byte data
# return hashlib.sha256(byte_data_str)
How would you go about doing this?
Edit: I've found the correct vernacular to find what I'm looking for. This is what I mean:
Alternative to python hash function for arbitrary objects
What is the quickest way to hash a large arbitrary object?
Create Hash for Arbitrary Objects?
I'm sure on of these contains a solution I seek.