[Python] Python - How to get Enum value by index

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have an Enum of days_of_the week in Python:

    class days_of_the_week(str, Enum):
    monday = 'monday'
    tuesday = 'tuesday'
    wednesday = 'wednesday'
    thursday = 'thursday'
    friday = 'friday'
    saturday = 'saturday'
    sunday = 'sunday'


    I want to access the value using the index.

    I've tried:

    days_of_the_week.value[index]


    days_of_the_week[index].value


    days_of_the_week.values()[index]


    and so on... But everything I tried didn't returned me the value of enum (eg. days_of_the_week[1] >>> 'tuesday')

    Is there a way?

    Continue reading...

Compartilhe esta Página