Accessing dict keys like an attribute?

前端 未结 27 2723
南笙
南笙 2020-11-22 04:22

I find it more convenient to access dict keys as obj.foo instead of obj[\'foo\'], so I wrote this snippet:

class AttributeDict(dict         


        
27条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 05:07

    Apparently there is now a library for this - https://pypi.python.org/pypi/attrdict - which implements this exact functionality plus recursive merging and json loading. Might be worth a look.

提交回复
热议问题