Accessing dict keys like an attribute?

前端 未结 27 2642
南笙
南笙 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:10

    tuples can be used dict keys. How would you access tuple in your construct?

    Also, namedtuple is a convenient structure which can provide values via the attribute access.

提交回复
热议问题