How can I make a dictionary that marks itself when it's modified?

Christian Tismer tismer at
Thu Jan 12 20:23:10 EST 2006

Steve Holden wrote:
> Christian Tismer wrote:
>> Just to add a word that I forgot:
>> Adhering to the subject line, the intent is to track modifications
>> of a dict.
>> By definition, modification of a member of a dict without replacing
>> the value is not considered a dict change.
> Well, I agree. But I suppose much depends on exactly what the OP meant 
> by "... add a new element or alter an existing one". The post did follow 
> that with "(the values in the dict are mutable)", which is presumably 
> why garabik-2500 proposed catching __getitem__ as well as __setitem__.

Yes, I understood this after reading more. Probably easier to
solve if the problem is spelled more specifically.

> I merely wanted to point out (not to you!) that there was no effective 
> way to capture a change to a mutable item without, as you say, modifying 
> the element classes.

You are completely right. This is asking for too much, unless one is
prepared to heavily modify the interpreter for debugging purposes,
which actually might be a way to solve the specific problem, once.

cheers - chris

Christian Tismer             :^)   <mailto:tismer at>
tismerysoft GmbH             :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A     :    *Starship*
14109 Berlin                 :     PGP key ->
work +49 30 802 86 56  mobile +49 173 24 18 776  fax +49 30 80 90 57 05
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?

More information about the Python-list mailing list