How to get all values from python enum class?
Based on the answer by @Jeff, refactored to use a classmethod
so that you can reuse the same code for any of your enums:
from enum import Enumclass ExtendedEnum(Enum): @classmethod def list(cls): return list(map(lambda c: c.value, cls))class OperationType(ExtendedEnum): CREATE = 'CREATE' STATUS = 'STATUS' EXPAND = 'EXPAND' DELETE = 'DELETE'print(OperationType.list())
Produces:
['CREATE', 'STATUS', 'EXPAND', 'DELETE']