读书人

python 字典的扩充变形

发布时间: 2013-10-29 12:07:57 作者: rapoo

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

读书人网 >perl python

热点推荐