小编Nit*_*jan的帖子

从 python 中的列表生成枚举类

假设我想创建以下枚举类:

from enum import Enum, unique

@unique
class Indication(Enum):
    Fruit1 = 'apple'
    Fruit2 = 'orange'
    Fruit3 = 'banana'
Run Code Online (Sandbox Code Playgroud)

我想从 python 列表创建它,即

Listoffruits = [('Fruit1', 'apple'),  ('Fruit2', 'orange'), ('Fruit3',  'banana')]
Run Code Online (Sandbox Code Playgroud)

如何有效地做到这一点?

python-3.x

3
推荐指数
1
解决办法
8719
查看次数

标签 统计

python-3.x ×1