python中枚举图像
Until now, if you wanted to use enumeration types in Python you had to fall back to a class-attribute approach:
到现在为止,如果您想在Python中使用枚举类型,则必须回退到类属性方法:
>>> >>> class class ColorColor (( objectobject ):
):
... ... RED RED = = 1
1
... ... GREEN GREEN = = 2
2
... ... BLUE BLUE = = 3
3
...
...
>>> >>> printprint (( ColorColor .. REDRED )
)
1
1
This has different downsides, for example with representation (Color.RED is represented as an integer, not as a color type) and comparability (Color.RED will be equal to HttpResponses.INTERNAL_SERVER_ERROR if both have the value 1).
这具有不同的缺点,例如在表示形式( Color.RED表示为整数,而不是颜色类型)和可比性(如果Color.RED都等于1则等于HttpResponses.INTERNAL_SERVER_ERROR )。
Enter PEP 435, which was accepted by Guido today. It specifies a new base class which can be subclassed to create a custom enumeration.
输入PEP 435 ,今天Guido接受了。 它指定了一个新的基类,可以将其子类化以创建自定义枚举。
快速开始 (Quickstart)
Declaration:
宣言:
Representation:
表示:
>>> >>> printprint (( ColorColor .. redred )
)
ColorColor .. red
red
>>> >>> printprint (( reprrepr (( ColorColor .. redred ))
))
<< ColorColor .. redred : : 11 >
>
Iteration:
迭代:
Programmatic access:
程序访问:
>>> >>> ColorColor (( 11 )
)
ColorColor .. red
red
>>> >>> ColorColor [[ 'blue''blue' ]
]
ColorColor .. blue
blue
There’s even more awesome stuff you can do with those enums. For more information, refer to the proposal.
您可以使用这些枚举来做更多很棒的事情。 有关更多信息,请参阅建议 。
我可以使用这个了吗? (Can I already use this?)
Yes and no. The PEP will be included in Python 3.4. But if you want to start using it right now, you can use the flufl.enum library which is the base implementation for PEP 435 and works for Python ≥2.7 and ≥3.2.
是的,没有。 PEP将包含在Python 3.4中。 但是,如果您想立即开始使用它,可以使用flufl.enum库,它是PEP 435的基本实现,适用于Python≥2.7和≥3.2。
python中枚举图像