Complexe枚举的数据结构。
pycatalog的Python项目详细描述
catalog是用于存储复杂枚举的数据结构。它为成员查找提供了一个干净的定义模式和几个选项。
支持Python2.7、3.3+
安装
pip install pycatalog
用法
from catalog import Catalog class Color(Catalog): _attrs = 'value', 'label', 'other' red = 1, 'Red', 'stuff' blue = 2, 'Blue', 'things' # Access values as Attributes > Color.red.value 1 > Color.red.label 'Red' # Call to look up members by attribute value > Color('Blue', 'label') Color.blue # Calling without attribute specified assumes first attribute defined in `_attrs` > Color(1) Color.red
属性
_attrs:定义成员属性的名称。(默认值:['value'])
_member_class:重写用于创建成员的类。通过扩展CatalogMember创建自定义成员类。
方法
_zip:将所有成员作为元组返回。如果属性作为位置参数提供,则仅 属性将包括在内,并按顺序排列。否则,所有属性都包含在后面 成员名称。
> Color._zip() (('red', 1, 'Red', 'stuff'), ('blue', 2, 'Blue', 'things')) > Colot._zip('value', 'label') ((1, 'Red'), (2, 'Blue'))
更改日志
1.2.0-添加对Python2的支持。(方向不对。我知道)
1.1.1-添加_zip方法
1.0.0-初始构建和打包