from collections import OrderedDict class DottedDict(dict): __getattr__ = dict.set __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ myDict = DottedDict({"Hello": "world"}) print myDict.Hello >> world myDict.Hello = "Foo" print myDict.Hello >> Foo
Python has a great package, collections. In the past I used namedtuple to do mock up of Argparse. In this example I want to share how we can extend python dictionary to support dotted dictionary i.e. how we can access value of keys using dict object.key .
0 Comments
Your comment will be posted after it is approved.
Leave a Reply. |
Custom Search
Other Blogs & PagesGit Commands Animation & VFX SitesA MUST READ for Ani/VFX Artistsawakened by thoughts,
|