[Python] Support for Enum arguments in argparse

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

  1. Stack

    Stack Membro Participativo

    Is there a better way of supporting Enums as types of argparse arguments than this pattern?

    class SomeEnum(Enum):
    ONE = 1
    TWO = 2

    parser.add_argument('some_val', type=str, default='one',
    choices=[i.name.lower() for i in SomeEnum])
    ...
    args.some_val = SomeEnum[args.some_val.upper()]

    Continue reading...

Compartilhe esta Página