`
pypy
  • 浏览: 90706 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

python 字典的扩展变形

阅读更多
class AttrDict(dict):

    """

    http://stackoverflow.com/questions/4984647/\

    accessing-dict-keys-like-an-attribute-in-python

    http://bugs.python.org/issue1469629

    """

    def __init__(self, source):

        super(AttrDict, self).__init__(source)

 

    def __getattr__(self, key):

        return self[key]

 

    def __setattr__(self, key, value):

        self[key] = value

0
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics