I need to compute a "hash" which allows me to uniquely identify an object, both it's contents and the parent class.
By comparing these "hashes" i want to be able to tell if an object has changed since the last time it was scanned.
I have found plenty of examples on how to make an object hashable, however not so much about how to compute a hash of the parent class.
It is important to note comparisons are made during different executions. I say this because I think comparing the id() of the object since the id/address of the object might be different for different executions.
I thought of resorting to inspect but I fear it might not be very efficient, also I am not very sure how that would work if the object's parent class is inheriting from another class.
If I had access to the actual memory raw data where the instance and the class' code is stored, I could just compute the hash of that.
Any ideas?
__dict__property if you want to know if it's changed since the last check. I don't think that taking its class into account is important here.hash()? Can you expand on that?foo, an instance ofclass Foo, and dofoo.bar = 1,hash(foo)will generate a value that will remain the same after you dofoo.bar = 2. OP wants to detect this kind of change.hash(repr(obj.__dict__))repris not reliable in this case since it won't give you the keys in a fixed order, nor will it give you ordered keys in dicts that the object might contain.