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

Raymond Hettinger python at rcn.com
Fri Jan 13 01:43:53 EST 2006


[sandravandale at yahoo.com]
> It's important that I can read the contents of the dict without
> flagging it as modified, but I want it to set the flag the moment I add
> a new element or alter an existing one (the values in the dict are
> mutable), this is what makes it difficult. Because the values are
> mutable I don't think you can tell the difference between a read and a
> write without making some sort of wrapper around them.
>
> Still, I'd love to hear how you guys would do it.

Take a look at shelve.py to see how Alex Martelli solved a similar
problem.  His solution kicks in when writeback=True.  The module
docstring elaborates on the problem and solution.




More information about the Python-list mailing list