0

How is it possible using argparse to define a set of optional arguments, out of which choosing at least one is mandatory.

For instance, myscript could have optional arguments like -a -b and -c, and I want to ensure that at least one out of these is specified, but at the same time specifying many of them is also a valid call. See below examples:

myscript -input inputfile -output outputfile -> invalid 
myscript -input inputfile -output outputfile -a -> valid 
myscript -input inputfile -output outputfile -b -> valid 
myscript -input inputfile -output outputfile -c -> valid 
myscript -input inputfile -output outputfile -a -b -> valid 
myscript -input inputfile -output outputfile -a -c -> valid 
myscript -input inputfile -output outputfile -a -b -c -> valid 
myscript -input inputfile -output outputfile -x -> invalid
pppery
  • 3,550
  • 19
  • 28
  • 41
  • Whoever closed my question, please note that the suggested answer is NOT an answer to my question. – user12187772 Jan 26 '22 at 19:00
  • Can you be more specific about *why* the ideas presented in the linked duplicate don't apply (or can't be adapted) to your situation? – chepner Jan 26 '22 at 19:12
  • 2
    Actually the question does match. The answers explore some alternatives, but none fully answers the question. `argparse` does not provide a means to do this. You have to test for a required value yourself, as shown in the accepted answer. – hpaulj Jan 26 '22 at 19:18

0 Answers0