programing

값별 열거 이름 가져오기

bestprogram 2023. 6. 6. 10:24

값별 열거 이름 가져오기

어떤 표준적인 방법이 있습니까?Enumeration names by value?

예:

class Example(enum.Enum):
    one = 1
    two = 2

ex_variable = 1

정해진ex_variableExample.one.name 에 포함된 문자열을 얻을 수 있습니까?

>>> Example(1).name
'one'

Python 문서도 참조하십시오.

열거형 구성원에 프로그래밍 방식으로 액세스하는 방법

>>> Example(ex_variable).name
'one'

언급URL : https://stackoverflow.com/questions/38716288/get-enumeration-name-by-value