Cool! I never thought of that. That's a great snippet.
I'll forward this to the python-ideas list. I don't think the
python-dev people want this discussion to continue on their mailing
list.
_______________________________________________
Python-ideas mailing list
Python...@python.org
http://mail.python.org/mailman/listinfo/python-ideas
The only thing I would add is obj.copy(), to ensure that the original
dictionary is unchanged.
class using(object):
def __init__(self, obj):
self._wrappee = obj.copy()
You're right, I would need to do more work to get it to mimic the
underlying object. I think I will stick with Oleg's suggestion to
subclass dict for now; it's great for unit tests. Thanks for the
idea, though.
class ReplaceableDict(dict):
def replace(self, **kwargs):
'Works for replacing string-based keys'
return dict(self.items() + kwargs.items())