argparse csv + choices

N

Neal Becker

I'm trying to combine 'choices' with a comma-seperated list of options, so I
could do e.g.,

--cheat=a,b

parser.add_argument ('--cheat', choices=('a','b','c'), type=lambda x:
x.split(','), default=[])

test.py --cheat a
error: argument --cheat: invalid choice: ['a'] (choose from 'a', 'b', 'c')

The validation of choice is failing, because parse returns a list, not an item.
Suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top