sublcassing dict without losing functionality
Steven Bethard
steven.bethard at gmail.com
Mon Nov 1 16:35:36 EST 2004
Mathias Waack <M.Waack <at> gmx.de> writes:
>
> How about starting with UserDict (source comes with your python
> distribution) and modifying it for your needs?
I'm trying to avoid a huge code bloat for something that should be relatively
simple. Modifying and using UserDict would give me some 60+ lines of code to do
something I would hope could be done in much less. A somewhat better option
might be to copy/paste and slightly modify the __init__ and update code from
UserDict which do more or less what I want... But of course, this has the
problem of any copy/paste solution -- it will inevitably turn into a pain to
sync. What happens if dict acquires a new keyword argument? I have to update
my class again...
The code is not hard to write, but it *is* already written for the dict object.
If there's any way to take advantage of that fact, I'd like to.
Steve
More information about the Python-list
mailing list