Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33864

Re: argparse -- mutually exclusive sets of arguments?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: argparse -- mutually exclusive sets of arguments?
Date 2012-11-23 13:56 -0500
References <roy-DDAE52.13462523112012@news.panix.com>
Newsgroups comp.lang.python
Message-ID <mailman.241.1353697034.29569.python-list@python.org> (permalink)

Show all headers | View raw


On 11/23/2012 1:46 PM, Roy Smith wrote:
> My command either takes two positional arguments (in which case, both
> are required):
>
> $ command foo bar
>
> or the name of a config file (in which case, the positional arguments
> are forbidden):
>
> $ command --config file
>
> How can I represent this with argparse; add_mutually_exclusive_group()
> isn't quite the right thing.  It could specify that foo and --config are
> mutually exclusive, but not (as far as I can see) the more complicated
> logic described above.

Make the two positional arguments be one duple?
Or tell argparse that all three are optional and handle the 'more 
complicated logic' in your own code after argparse returns.


-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

argparse -- mutually exclusive sets of arguments? Roy Smith <roy@panix.com> - 2012-11-23 13:46 -0500
  Re: argparse -- mutually exclusive sets of arguments? Terry Reedy <tjreedy@udel.edu> - 2012-11-23 13:56 -0500
  Re: argparse -- mutually exclusive sets of arguments? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-23 18:07 -0700

csiph-web