小编shr*_*shr的帖子

枚举不能在Python 2.7中迭代

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
Run Code Online (Sandbox Code Playgroud)

运行此代码时出错

  for shake in Shake:
TypeError: 'type' object is not iterable
Run Code Online (Sandbox Code Playgroud)

EnumPython 2.7中不支持迭代吗?如果我们创建该Enum类型的对象,它就有效.

python enums python-2.7

4
推荐指数
1
解决办法
2838
查看次数

标签 统计

enums ×1

python ×1

python-2.7 ×1