hysyeah

知易行难


  • 首页

  • 分类

  • 标签

  • 归档

  • 关于

  • 搜索

定义一个可以通过属性访问的字典

发表于 2017-09-15 分类于 python
In [6]: class attrdict(dict):
...:        def __getattr__(self, attr):
...:            try:
...:                return self[attr]
...:            except KeyError:
...:                raise AttributeError(attr)
...:

In [7]: op = attrdict(AND='and',OR='or')

In [8]: op
Out[8]: {'AND': 'and', 'OR': 'or'}

In [9]: op.AND
Out[9]: 'and'

In [10]: op.OR
Out[10]: 'or'

Ref:
1.来自peewee源码

mysql的limit,offset分页
python各时间段获取和时间类型的转换

hys

329 日志
30 分类
35 标签
hysyeah.top © 2019-2025 粤ICP备19077752号