Quantcast
Channel: How to use a dot "." to access members of dictionary? - Stack Overflow
Viewing all articles
Browse latest Browse all 40

Answer by volodymyr for How to use a dot "." to access members of dictionary?

$
0
0

If you want to pickle your modified dictionary, you need to add few state methods to above answers:

class DotDict(dict):"""dot.notation access to dictionary attributes"""    def __getattr__(self, attr):        return self.get(attr)    __setattr__= dict.__setitem__    __delattr__= dict.__delitem__    def __getstate__(self):        return self    def __setstate__(self, state):        self.update(state)        self.__dict__ = self

Viewing all articles
Browse latest Browse all 40

Trending Articles