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
运行此代码时出错
for shake in Shake:
TypeError: 'type' object is not iterable
Python 2.7中的Enum
不支持迭代吗?如果我们创建Enum
类型的对象,它就可以工作。