Hacker News new | past | comments | ask | show | jobs | submit login

    class attrdict(defaultdict):
        def __getattr__(self, key): return self[key]
        def __setattr__(self, key, val): self[key]=val

    def tree(): return attrdict(tree)
attrdict is indeed a useful thing to have around. I usually base it off on the built in "dict", but as this example shows, it is useful on top of "defaultdict" as well.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: