[Python] Dynamically create an enum with custom values in Python? [duplicate]

Discussão em 'Python' iniciado por Stack, Agosto 2, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to create an enum type at runtime by reading the values in a YAML file. So I have this:

    # Fetch the values
    v = {'foo':42, 'bar':24}

    # Create the enum
    e = type('Enum', (), v)


    Is there a proper way to do it? I feel calling type is not a very neat solution.

    Continue reading...

Compartilhe esta Página