【发布时间】:2017-03-07 21:23:49
【问题描述】:
我有一个简单的 Python 2.7 枚举:
from enum import Enum
class Label(enum):
RedApple = 1
GreenApple = 2
我希望能够使用不区分大小写的键创建枚举对象:
fruitname = "redapple"
a = Label[fruitname]
我尝试创建一个__init__ 方法:
def __init__(self, key):
super(Label, self).__init__()
pass # do comparison here
但我总是遇到错误:
super(Label, self).__init__()
NameError: global name 'Label' is not defined
我想对key.lower().strip() 进行比较。这甚至可能吗?
【问题讨论】:
标签: python python-2.7 enums