python 类似 dict
来源:互联网 发布:快商通网络 编辑:程序博客网 时间:2024/04/28 02:26
工作中的代码,功能不错。
class Storage(dict):
"""A Storage object is like a dictionary except `obj.foo` can be used
in addition to `obj['foo']`.
>>> o = storage(a=1)
>>> o.a
1
>>> o['a']
1
>>> o.a = 2
>>> o['a']
2
>>> del o.a
>>> o.a
Traceback (most recent call last):
...
AttributeError: 'a'
"""
def __getattr__(self, key):
try:
return self[key]
except KeyError, k:
raise AttributeError, k
def __setattr__(self, key, value):
self[key] = value
def __delattr__(self, key):
try:
del self[key]
except KeyError, k:
raise AttributeError, k
def __repr__(self):
return '<Storage ' + dict.__repr__(self) + '>'
- python 类似 dict
- python dict
- python dict
- python dict
- Python---dict
- python-dict
- python-dict
- Python dict
- Python dict
- Python-dict
- Python Dict
- 【Python】【Dict】dict 基本用法
- python中的dict.
- python - 基础类型 - dict
- python dict访问
- Python Dict 排序
- python之dict
- python dict sort
- js本地储存userData实例
- [精华] ITPUB 索引树-mongodb 知识体系
- 网络存储系统NSS基准性能测试(7.31)
- VC2010下编译log4cxx(windows环境下)
- mysql长连接和短连接的问题
- python 类似 dict
- ADS1.2 Error:(Fatal) L6002u:could not open file
- 在RedHat Linux 9下安装小企鹅中文输入法
- 深刻理解C#的传值调用和传引用调用
- LayoutInflater 添加布局
- C++日志库log4cplus使用手册
- httpd: Could not reliably determine the server's fully qualified domain name
- 1.3 设计一个算法移除字符串中的重复字符,算法不使用额外缓冲。并对你的算法设计测试用例。
- Cocos2d-x lua的随机函数