[Python] argparse's "required" ignored in the help screen?

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    Consider the following code:

    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('-o', required=True, nargs=1)
    parser.parse_args(['-h'])


    Why am I getting the following output even if I said that -o is required?

    usage: test.py [-h] -o O

    optional arguments:
    -h, --help show this help message and exit
    -o O


    I would expect the help text to say that -o is required.

    Continue reading...

Compartilhe esta Página