Detecting changes to a dict

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Sep 27 05:36:21 EDT 2009


I'm pretty sure the answer to this is No, but I thought I'd ask just in 
case... 

Is there a fast way to see that a dict has been modified? I don't care 
what the modifications are, I just want to know if it has been changed, 
where "changed" means a key has been added, or deleted, or a value has 
been set. (Modifications to mutable values aren't important.) In other 
words, any of these methods count as modifying the dict:

__setitem__
__delitem__
clear
pop
popitem
setdefault
update

Of course I can subclass dict to do this, but if there's an existing way, 
that would be better.


-- 
Steven



More information about the Python-list mailing list