[Tutor] Groups of mutually exclusive options

Steven D'Aprano steve at pearwood.info
Tue Apr 22 05:23:08 CEST 2014

On Mon, Apr 21, 2014 at 08:26:41PM -0400, rail shafigulin wrote:

> For example say I have a the script with called myscript.py which can take
> two groups of options
> group1
>     option1a
>     option1b
>     option1c
> group2
>     option2a
>     option2b
>     otpion2c
> I can run this script only with the following options
> myscript.py --option1a --option1b --option1c
> or
> myscript.py --option2a --option2b --option2c

Normally the way to handle that with argparse is to define subcommands,
and write something like this:

myscript.py spam --option1a --option1b --option1c
myscript.py eggs --option2a --option2b --option2c


I don't think there is any directly supported way to handle it in 
argparse without the subcommands.


More information about the Tutor mailing list