Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CMCDragonkai/0118e112e3d0de377f71bf92efc7ace6 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/0118e112e3d0de377f71bf92efc7ace6 to your computer and use it in GitHub Desktop.
Python `subprocess.run` and `argparse` nargs (multi-value options) is tricky

Python subprocess.run and argparse nargs (multi-value options) is tricky

If you have a Python program that uses argparse nargs to specify multi-value options then you need to make sure that each value is its own parameter.

import subprocess

subprocess.run(
    [
        'command',
        '--multi-option', 'value1', 'value2',
        '--anotheroption=value'
    ])

If you don't do the above, the subprocess command will complain that the option wasn't set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment