Quantcast
Viewing all articles
Browse latest Browse all 40

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

The answer of @derek73 is very neat, but it cannot be pickled nor (deep)copied, and it returns None for missing keys. The code below fixes this.

Edit: I did not see the answer above that addresses the exact same point (upvoted). I'm leaving the answer here for reference.

class dotdict(dict):    __setattr__ = dict.__setitem__    __delattr__ = dict.__delitem__    def __getattr__(self, name):        try:            return self[name]        except KeyError:            raise AttributeError(name)

Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>