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


Groups > comp.lang.python > #51973

RE: [argparse] mutually exclusive group with 2 sets of options

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <jcasale@activenetwerx.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; 'subject:group': 0.05; 'args': 0.07; 'incompatible': 0.07; 'params': 0.09; 'parsed': 0.09; 'parsing': 0.09; 'sub': 0.09; 'cli': 0.16; 'conditional': 0.16; 'declared': 0.16; 'goal,': 0.16; 'omitting': 0.16; 'ops': 0.16; 'received:172.18.0': 0.16; 'subject:argparse': 0.16; 'subject:options': 0.16; 'followed': 0.16; 'typing': 0.19; 'subject:] ': 0.20; 'code,': 0.22; 'tests': 0.22; 'to:name:python-list@python.org': 0.22; 'install': 0.23; 'certainly': 0.24; "i've": 0.25; 'performing': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'mode': 0.30; 'waste': 0.30; 'probably': 0.32; 'url:python': 0.33; "i'd": 0.34; 'problem': 0.35; 'subject:with': 0.35; 'something': 0.35; 'charset :us-ascii': 0.36; 'similar': 0.36; 'url:org': 0.36; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'commands': 0.60; 'received:unknown': 0.61; "you're": 0.61; 'love': 0.65; 'here': 0.66; 'between': 0.67; 'tough': 0.93
X-Cloudmark-SP-Filtered true
X-Cloudmark-SP-Result v=1.1 cv=PW5KkOyi2N+7koGLNuH5QW2TYwO584XWNobLzFE45Rc= c=1 sm=1 a=CRTDazI5n6YA:10 a=bMjXrhc6l3kA:10 a=7PYXob_7ZXMA:10 a=BLceEmwcHowA:10 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=oNw28mxuUhXRB3mVwYQ4Ag==:17 a=8AHkEIZyAAAA:8 a=hryfGH_EDMI4JriAw5oA:9 a=CjuIK1q_8ugA:10 a=dTQCBY7ILbYA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117
From "Joseph L. Casale" <jcasale@activenetwerx.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: [argparse] mutually exclusive group with 2 sets of options
Thread-Topic [argparse] mutually exclusive group with 2 sets of options
Thread-Index AQHOkLjcN8jSCPYJrk+6yEPX8qUb5JmHDl2A///IOqA=
Date Mon, 5 Aug 2013 17:11:30 +0000
References <51fdb81b$0$2423$426a74cc@news.free.fr> <6db08670-52e8-4ca2-aff4-82d611a29da6@googlegroups.com>
In-Reply-To <6db08670-52e8-4ca2-aff4-82d611a29da6@googlegroups.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [172.18.0.200]
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.215.1375722699.1251.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375722699 news.xs4all.nl 16010 [2001:888:2000:d::a6]:53152
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51973

Show key headers only | View raw


> You can probably do something similar using sub commands
> (http://docs.python.org/2/library/argparse.html#sub-commands).

The problem here is that argparse does not pass the subparser into the
parsed args and shared args between subparsers need to be declared
each time. Come execution time, when you have shared args you end
up testing for various incantations of the invoked code, you're better
off omitting subparsers and performing conditional tests after parsing
for incompatible combinations.

It's a waste of typing to write out a mode followed by params to achieve
the ops goal, I've hit the same limitation. Certainly a weakness of argparse
in my opinion. It's also a tough sell to force a user to install a package just
for the cli if you go with docopt. I'd love to see argparse expand or docopt
get included...

jlc

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


Thread

[argparse] mutually exclusive group with 2 sets of options Francois Lafont <francois.lafont@nospam.invalid> - 2013-08-04 04:10 +0200
  Re: [argparse] mutually exclusive group with 2 sets of options Francois Lafont <francois.lafont@nospam.invalid> - 2013-08-05 04:05 +0200
    Re: [argparse] mutually exclusive group with 2 sets of options Joshua Landau <joshua@landau.ws> - 2013-08-05 04:53 +0100
  Re: [argparse] mutually exclusive group with 2 sets of options Miki Tebeka <miki.tebeka@gmail.com> - 2013-08-05 07:11 -0700
    RE: [argparse] mutually exclusive group with 2 sets of options "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-08-05 17:11 +0000
    Re: [argparse] mutually exclusive group with 2 sets of options Francois Lafont <francois.lafont@nospam.invalid> - 2013-08-06 00:13 +0200
  Re: [argparse] mutually exclusive group with 2 sets of options Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2013-08-05 22:01 +0200
    Re: [argparse] mutually exclusive group with 2 sets of options Francois Lafont <francois.lafont@nospam.invalid> - 2013-08-06 00:34 +0200
      Re: [argparse] mutually exclusive group with 2 sets of options Francois Lafont <francois.lafont@nospam.invalid> - 2013-08-07 01:18 +0200
        Re: [argparse] mutually exclusive group with 2 sets of options Francois Lafont <francois.lafont@nospam.invalid> - 2013-08-07 01:36 +0200
  RE: [argparse] mutually exclusive group with 2 sets of options "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-08-05 22:15 +0000

csiph-web