Python2.7中的枚举不可编辑

2024-05-16 11:06:48 发布

您现在位置:Python中文网/ 问答频道 /正文

from enum import Enum

class Shake(Enum):
    __order__ = 'vanilla chocolate cookies mint' # only needed in 2.x
    vanilla = 7
    chocolate = 4
    cookies = 9
    mint = 3

for shake in Shake:
    print shake

运行此代码时出错

^{pr2}$

Python2.7中的Enum不支持迭代吗?如果我们创建一个Enum类型的对象,就可以了。在


Tags: infromimportonlyorderenumclasscookies