How to pass a list as a command-line argument after equals sign with argparse?

Viewed 88

The documented way to pass a list of arguments using argparse uses the following syntax

parser = argparse.ArgumentParser()
parser.add_argument("--list", nargs="+", default=["a", "b"])
value = parser.parse_args()

In the SHELL

$ python3 example.py --list a b c

$ ['a', 'b', 'c']

The arguments Im working with have leading dashes and require the use of = to not be misinterpreted by argparse as another option (See this question)

$ python3 example.py --list=-a

$ ['-a']

I would like to pass in a list of arguments using the = syntax. However, Im not sure how to accomplish this. I'm looking for something like the following to work:

$ python3 example.py --list=-a,-b

$ ['-a','-b']

0 Answers
Related