sublcassing dict without losing functionality
M.Waack at gmx.de
Mon Nov 1 21:52:52 CET 2004
Steven Bethard wrote:
> I'd like to subclass dict to disallow overwriting of keys,
> something like:
> The problem is, dict doesn't appear to call __setitem__ in any of
> the __init__ forms, so none of the following raise errors as I'd
> like them to:
> etc. Is there a simple way to override this behavior in dict
> having to rewrite __init__? There are so many cases in
> dict.__init__ that I'm hesitant to try to reproduce them all...
How about starting with UserDict (source comes with your python
distribution) and modifying it for your needs?
More information about the Python-list