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源码