Saturday, 11 September 2021

Python: Get enum member name

Using the property ‘name’, you can get enum member name.

 

enumMemberName.py

from enum import Enum

class Day(Enum):
    MONDAY = 1
    TUESDAY = 2
    WEDNESDAY = 3
    THURSDAY = 4
    FRIDAY = 5
    SATURDAY = 6
    SUNDAY = 7

for day in Day:
    print(day.name)

 

Output

MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY

 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment