枚举在Python 2.7中不可迭代 [英] Enum not iterable in Python 2.7

查看:100
本文介绍了枚举在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

运行此代码时出错

  for shake in Shake:
TypeError: 'type' object is not iterable

Python 2.7中的 Enum 是否不支持迭代?如果我们创建 Enum 类型的对象,它将起作用。

Is iteration not supported for Enum in Python 2.7? It works if we make a object of the Enum type.

推荐答案

Python 3.4枚举类型的backport是 enum34 ,而不是枚举

The backport of the Python 3.4 Enum type is enum34, not enum.

这篇关于枚举在Python 2.7中不可迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆