python中枚举图像_Python中的枚举

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。

翻译自: https://www.pybloggers.com/2013/05/enums-in-python/

python中枚举图像

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值