Accessing dict keys like an attribute?

前端 未结 27 2113
南笙
南笙 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 04:54

    You can have all legal string characters as part of the key if you use array notation. For example, obj['!#$%^&*()_']

提交回复
热议问题