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


Groups > comp.lang.python > #49341

Re: Why is the argparse module so inflexible?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'string': 0.09; 'arguments': 0.09; 'parsers': 0.09; 'parsing': 0.09; 'propagate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'required,': 0.09; 'subject:Why': 0.09; 'subject:module': 0.09; 'jan': 0.12; 'letting': 0.16; 'non-default': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:argparse': 0.16; 'systemexit': 0.16; 'exception': 0.16; 'so.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'module': 0.19; 'user.': 0.19; 'command': 0.22; 'input': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'parse': 0.24; 'passes': 0.24; "i've": 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'andrew': 0.30; 'that.': 0.31; 'catching': 0.31; 'context.': 0.31; 'restricted': 0.31; "user's": 0.31; '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; 'subject:?': 0.36; 'application': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'above,': 0.60; 'tell': 0.60; 'received:173': 0.61; 'great': 0.65; 'dsl': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Why is the argparse module so inflexible?
Date Thu, 27 Jun 2013 14:05:09 -0400
References <51CC35F4.3040609@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
In-Reply-To <51CC35F4.3040609@gmail.com>
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.3936.1372356326.3114.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372356326 news.xs4all.nl 15912 [2001:888:2000:d::a6]:44142
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49341

Show key headers only | View raw


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.'.

-- 
Terry Jan Reedy

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


Thread

Re: Why is the argparse module so inflexible? Terry Reedy <tjreedy@udel.edu> - 2013-06-27 14:05 -0400

csiph-web