Re: Dictionary with additional attributes

2011-02-22 Thread goodman
On Feb 22, 1:32 pm, Robert Kern wrote: > On 2/22/11 1:49 PM, goodman wrote: > > > Hi, my question is this: Is it a bad idea to create a wrapper class > > for a dictionary so I can add attributes? > > Nope. I do recommend adding a custom __repr__(), though. > Good point. Thanks -- http://mail.pyt

Re: Dictionary with additional attributes

2011-02-22 Thread Santoso Wijaya
Instead of inheriting a dict, why not composing a dict into your "model" class, like: class Model(object): def __init__(self, *args, **kwargs): self._probabilities = defaultdict(lambda: defaultdict(float)) @property def features(self): # insert

Re: Dictionary with additional attributes

2011-02-22 Thread Robert Kern
On 2/22/11 1:49 PM, goodman wrote: Hi, my question is this: Is it a bad idea to create a wrapper class for a dictionary so I can add attributes? Nope. I do recommend adding a custom __repr__(), though. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma

Dictionary with additional attributes

2011-02-22 Thread goodman
Hi, my question is this: Is it a bad idea to create a wrapper class for a dictionary so I can add attributes? E.g.: class DictWithAttrs(dict): pass More information: I'm using a nested defaultdict to store a machine-learning model, where the first key is a class, the second key is a feature,