[Python] Suppressing option processing after a non-option command-line argument

Discussão em 'Python' iniciado por Stack, Junho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am writing a wrapper script using argparse which accepts a list of arguments that are going to be passed to another program, and some options that are specific to my wrapper. To avoid confusion regarding which options go where, I want any appearance of a non-option argument to suppress processing further arguments as options, as if a -- argument appeared just before it. In other words, something similar to what xterm -e does.

    parse_known_args is obviously wrong, because it will ignore unknown options, and pick up options appearing after a non-option.

    What is the best way to accomplish this in Python? I would prefer to keep using argparse over parsing the command line manually.

    Continue reading...

Compartilhe esta Página