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


Groups > comp.lang.python > #18861

Re: Introspecting optparse/argparse objects

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!amsnews11.chello.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <edriscoll@wisc.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(at': 0.03; 'api.': 0.05; 'args': 0.05; 'suppose': 0.05; ':-)': 0.06; 'function,': 0.07; 'builtin': 0.09; 'content-type:multipart/signed': 0.09; 'data:': 0.09; 'filename:fname piece:signature': 0.09; 'of)': 0.09; 'optparse': 0.09; 'parsers': 0.09; 'positional': 0.09; 'subclass': 0.09; 'am,': 0.12; "'do": 0.16; '--help': 0.16; 'alex23': 0.16; 'content-type:application/pgp-signature': 0.16; 'driscoll': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname:signature.asc': 0.16; 'parser,': 0.16; 'wrote:': 0.18; 'wrap': 0.18; 'jan': 0.19; 'seems': 0.20; 'options.': 0.21; 'header:In-Reply-To:1': 0.22; 'figure': 0.23; 'interface': 0.23; '(though': 0.23; 'keyword': 0.24; 'code': 0.25; 'structure': 0.26; 'function': 0.27; 'weird': 0.29; "skip:' 10": 0.29; 'skip:b 20': 0.29; 'definition': 0.30; 'arguments.': 0.30; 'closer': 0.30; 'wraps': 0.30; 'least': 0.30; 'point,': 0.32; 'wanting': 0.32; 'list': 0.32; 'actual': 0.32; 'idea': 0.32; 'pretty': 0.32; "can't": 0.32; "won't": 0.33; 'header:User-Agent:1': 0.33; 'actually': 0.33; 'to:addr:python- list': 0.34; 'mix': 0.34; 'list.': 0.35; 'something': 0.35; 'subject:/': 0.35; '(for': 0.35; '...': 0.36; 'uses': 0.36; 'but': 0.37; 'received:192': 0.37; "there's": 0.37; 'received:128': 0.37; 'using': 0.38; 'some': 0.38; 'received:192.168.0': 0.38; 'e.g.': 0.39; 'feed': 0.39; 'option': 0.39; "i'd": 0.39; 'extend': 0.39; 'why': 0.39; "it's": 0.40; 'to:addr:python.org': 0.40; 'might': 0.40; 'received:192.168': 0.40; 'more': 0.61; 'took': 0.63; '"do': 0.67; '11,': 0.68; 'truth': 0.68; 'soon': 0.70; '11:26': 0.84
Date Wed, 11 Jan 2012 20:44:28 -0600
From Evan Driscoll <edriscoll@wisc.edu>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Introspecting optparse/argparse objects
References <mailman.4620.1326245218.27778.python-list@python.org> <ebde8bec-e6b5-4541-8765-14e9a9189ff3@b10g2000pbd.googlegroups.com>
In-Reply-To <ebde8bec-e6b5-4541-8765-14e9a9189ff3@b10g2000pbd.googlegroups.com>
X-Enigmail-Version 1.3.4
Content-Type multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigC4B2DA3A8497FAABF91A0AF4"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.4672.1326336337.27778.python-list@python.org> (permalink)
Lines 68
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1326336337 news.xs4all.nl 6896 [2001:888:2000:d::a6]:52706
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18861

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 1/11/2012 19:37, alex23 wrote:
> On Jan 11, 11:26 am, Evan Driscoll <edrisc...@wisc.edu> wrote:
>> (For a concrete idea of a use case, suppose that it did not
>> directly support the --help option and I wanted to write code that took
>> its place.)
> That's a pretty weird definition of 'concrete use case', but anyway...
It's actually closer to the truth than it might seem. I want to feed a
bash-completion-style thing, using the same data structure to both
figure out the possible completions and also do the actual parsing. "Do
the actual parsing" = optparse/argparse, while "figure out the possible
completions" = I need to be able to look at a list.

> If you're wanting to extend the behaviour of the options, won't you
> need to wrap them anyway?
I don't have any need to extend the parsers other than to get the list
of options. (Though now that you've brought that up, perhaps looking at
the _private fields in a subclass would be the best tradeoff? Hmmm.)

> But more to the point, you already have the data: you used it to
> create the options. Why not just keep a handle on that data and refer
> to what you need directly?
But now you're talking about wrapping the parser, because there's no
builtin way (at least that I know of) to store the information in such a
way that you can call the function, because it uses a mix of positional
and keyword arguments. E.g. I can't say just
    args = ('-f', '--foo', help='do foo')
    ...
    parser.add_argument(*args)
but would have to say something like
    args = ( ('-f', '-foo'), {'help': 'do foo'})
    ...
    parser.add_argument(*args[0], *args[1])
or something like that.

I'd want to add some function like 'make_option' which wraps all that
up, and then provide a nicer interface for add_argument, etc., and it
seems like pretty soon I're reimplementing the optparse API. :-) Or at
least it might be that way.

Evan

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


Thread

Introspecting optparse/argparse objects Evan Driscoll <edriscoll@wisc.edu> - 2012-01-10 19:26 -0600
  Re: Introspecting optparse/argparse objects alex23 <wuwei23@gmail.com> - 2012-01-11 17:37 -0800
    Re: Introspecting optparse/argparse objects Evan Driscoll <edriscoll@wisc.edu> - 2012-01-11 20:44 -0600

csiph-web