Dictionary Enhancement?

Michael Hudson mwh at python.net
Thu Oct 31 12:45:10 EST 2002


Rich Harkins <rich at worldsinfinite.com> writes:

> I was wondering if anyone else had been wanting to enhance Python
> dictionaries such that instead of raising KeyError in the case of errors
> that another method on the dictionary object, say __makeitem__ would be
> called to try to auto-generate an appropriate value.  That __makeitem__
> method would then either raise KeyError itself or return the value to
> insert into the dictionary and return through __getitem__.

This is falling-off-a-log easy in Python 2.2: just derive a subclass
from the dictionary.

Cheers,
M.

-- 
  I don't remember any dirty green trousers.
                                             -- Ian Jackson, ucam.chat



More information about the Python-list mailing list