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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC4B2DA3A8497FAABF91A0AF4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 1/11/2012 19:37, alex23 wrote: > On Jan 11, 11:26 am, Evan Driscoll 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 too= k >> 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" =3D optparse/argparse, while "figure out the possible= completions" =3D 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 =3D ('-f', '--foo', help=3D'do foo') ... parser.add_argument(*args) but would have to say something like args =3D ( ('-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 --------------enigC4B2DA3A8497FAABF91A0AF4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJPDkkMAAoJEAOzoR8eZTzgpQsH/Aqah/ub+YykexB0pLKT4A2y XnRMko7SOlyoaRMGPbMgjq08hVIQEQt3XEHTDIp5O9TvPucQDe9VOrDn9OrcuExH zfucBZmmEq3036k8pSicrXRRt6om+to/+LdDka8KRClkB2d58oZiNkNByvXzBzPD 7Tiv3Pbb+2T2NtmnMmGZs//BruaWoj9c5Rx32FareA+1W8Vz8wUyqpnP7kSZldDT p0vYLnhJN3yMWWbyGBxr4o1ADJNPdVI7fQL+9zMZ92DS83uNp8x9CqY8zrsdXDYQ wNGE2ZcFUy5bD6rKrHbEm82zIMKEFE2dOuECy5E8W67bTo5jEk/inAcTBog39Sg= =UzOx -----END PGP SIGNATURE----- --------------enigC4B2DA3A8497FAABF91A0AF4--