[Python] Does ArgumentParser support different arguments per file, ffmpeg style?

Discussão em 'Python' iniciado por Stack, Julho 15, 2025.

  1. Stack

    Stack Membro Participativo

    I want my application to work on several files and have a different set of options for each input file:

    python my.py -a file_a -b file_b --do-stuff=x file_c


    ffmpeg uses this idea for its command line arguments.

    I tried the following:

    parser = argparse.ArgumentParser()
    parser.add_argument("-a", action="store_true")
    parser.add_argument("-b", action="store_true")
    parser.add_argument("--do-stuff", type=str)
    parser.add_argument("files", type=pathlib.Path, nargs="+")
    args = parser.parse_args()


    And I get an error:

    error: unrecognized arguments: file_b file_c


    Can I use ArgumentParser to parse such a command line?

    Continue reading...

Compartilhe esta Página