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


Groups > comp.lang.python > #49344

Re: Why is the argparse module so inflexible?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
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; 'argument': 0.05; 'string': 0.09; 'arguments': 0.09; 'exception.': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'parsers': 0.09; 'parsing': 0.09; 'propagate': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'required,': 0.09; 'scripts,': 0.09; 'sentence': 0.09; 'subject:Why': 0.09; 'subject:module': 0.09; '~ethan~': 0.09; 'abort': 0.16; 'letting': 0.16; 'non-default': 0.16; 'optional': 0.16; 'reasonable.': 0.16; 'received:gateway01.websitewelcome.com': 0.16; 'reedy': 0.16; 'said.': 0.16; 'subject:argparse': 0.16; 'systemexit': 0.16; 'exception': 0.16; 'so.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'module': 0.19; 'user.': 0.19; 'not,': 0.20; 'command': 0.22; '>>>': 0.22; 'input': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'parse': 0.24; 'passes': 0.24; "shouldn't": 0.24; "i've": 0.25; 'tracker': 0.26; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'andrew': 0.30; 'returned': 0.30; 'work.': 0.31; 'that.': 0.31; '3.x': 0.31; '>>>>': 0.31; 'catching': 0.31; 'context.': 0.31; 'restricted': 0.31; "user's": 0.31; 'probably': 0.32; 'another': 0.32; 'quite': 0.32; 'trouble': 0.34; 'sense': 0.34; 'subject:the': 0.34; 'something': 0.35; 'usual': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'should': 0.36; 'application': 0.37; 'so,': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'little': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'above,': 0.60; 'dave': 0.60; 'tell': 0.60; 'received:173': 0.61; 'information': 0.63; 'become': 0.64; 'different': 0.65; 'great': 0.65; 'received:69.56': 0.68; 'transferred': 0.68; 'default': 0.69; 'behavior': 0.77; 'dsl': 0.84; 'nonsense.': 0.84; 'received:69.56.224': 0.84; 'angel': 0.91; 'shell,': 0.91
Date Thu, 27 Jun 2013 11:50:38 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Why is the argparse module so inflexible?
References <51CC35F4.3040609@gmail.com> <kqhusi$je5$1@ger.gmane.org> <51CC8205.5060906@davea.name> <kqi0s8$a5d$1@ger.gmane.org>
In-Reply-To <kqi0s8$a5d$1@ger.gmane.org>
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender ([173.12.184.233]) [173.12.184.233]:43584
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
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.3939.1372361841.3114.python-list@python.org> (permalink)
Lines 55
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372361841 news.xs4all.nl 15894 [2001:888:2000:d::a6]:33436
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49344

Show key headers only | View raw


On 06/27/2013 11:39 AM, Terry Reedy wrote:
> On 6/27/2013 2:18 PM, Dave Angel wrote:
>> On 06/27/2013 02:05 PM, Terry Reedy wrote:
>>> On 6/27/2013 8:54 AM, Andrew Berg wrote:
>>>> I've begun writing a program with an interactive prompt, and it needs
>>>> to parse input from the user.  I thought the argparse module would be
>>>> great for this,
>>>
>>> It is outside argparse's intended domain of application -- parsing
>>> command line arguments. The grammar for a valid string of command line
>>> arguments is quite restricted.
>>>
>>> Argparse is not intended for interactive processing of a domain-specific
>>> language (DSL). There are other parsers for that. But if the grammar for
>>> your DSL is restricted to what argparse can handle, using it is an
>>> interesting idea. But you need non-default usage for the non-default
>>> context.
>>>
>>>  > but unfortunately it insists on calling sys.exit() at
>>>> any sign of trouble instead of letting its ArgumentError exception
>>>> propagate so that I can handle it.
>>>
>>> When one tell argparse that something is *required*, that means "I do
>>> not want to see the user's input unless it passes this condition." After
>>> seeing an error message, the user can edit the command line and re-enter.
>>>
>>> If you do not mean 'required' in the sense above, do not say so.
>>> Catching SystemExit is another way to say 'I did not really mean
>>> required, in the usual mean of that term.'.
>>>
>>
>> That last sentence is nonsense.
>
> Not if you understand what I said.
>
>> If one is parsing the line the user  enters via raw_input(),
>
> input(), in 3.x
>
>> catching SystemExit so the program doesn't abort
>> is perfectly reasonable.  The user should be returned to his prompt,
>> which in this case is probably another loop through raw_input().
>
> Right, because 'required' means something a little different in the interactive context.
>
> I don't know if all the information in the original ArgumentError exception is transferred to the SystemExit exception.
> I expect not, and if so, and if multiple people are using argparse this way, it would be reasonable to request on the
> tracker that its current sys.exit behavior become default but optional in 3.4+. There might even be an issue already if
> one searched.

If the OP is writing an interactive shell, shouldn't `cmd` be used instead of `argparse`?  argparse is, after all, 
intended for argument parsing of command line scripts, not for interactive work.

--
~Ethan~

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


Thread

Re: Why is the argparse module so inflexible? Ethan Furman <ethan@stoneleaf.us> - 2013-06-27 11:50 -0700

csiph-web