On Mon, Feb 15, 2016 at 11:17 AM, Herman <sorsor...@gmail.com> wrote:
> I want to pass in the key to the default_factory of defaultdict and I found
> that defaultdict somehow can intercept my call to dict.__getitem__(self,
> key), so my class's __getitem__ have to catch a TypeError instead instead
> of KeyError. The following class is my code:

Save yourself a lot of trouble, and just override __missing__:

class DefaultDictWithEnhancedFactory(collections.defaultdict):
    def __missing__(self, key):
        return self.default_factory(key)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to