Use argparse to define an option that takes a string consisting of any letters from a given set

3 days ago 1
ARTICLE AD BOX

Using argparse, I'd like to support the following syntax:

asm2k.py -o XXXXX bbl.asm

Specifically, the -o option can take 1 or more letters, where the letters are from the set of "ARLQTNZCFXPB".

My attempt with just ABC for brevity:

parser.add_argument('-o', '--options', nargs='+', choices=('A','B','C'), help='Control Options')

But this doesn't allow combinations like -o AC or -o BCA. Is this use case supported?

mkrieger1's user avatar

mkrieger1

24.4k7 gold badges69 silver badges85 bronze badges

jwest's user avatar

New contributor

jwest is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1

Read Entire Article