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


Groups > comp.lang.python > #49319

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!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
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; 'sys': 0.07; 'ugly': 0.07; 'arguments': 0.09; 'caller': 0.09; 'exception.': 0.09; 'imported': 0.09; 'propagate': 0.09; 'subject:Why': 0.09; 'subject:module': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'useful,': 0.14; 'attributes).': 0.16; 'letting': 0.16; 'overriding': 0.16; 'raised,': 0.16; 'subject:argparse': 0.16; 'supplied': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'module': 0.19; 'normally': 0.19; 'user.': 0.19; 'meant': 0.20; '>>>': 0.22; 'input': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'case.': 0.24; 'parse': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'wonder': 0.29; "doesn't": 0.30; 'andrew': 0.30; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'terminate': 0.31; 'figure': 0.32; 'trouble': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'display': 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'handle': 0.38; 'does': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'most': 0.60; 'information': 0.63; 'great': 0.65; 'to:addr:gmail.com': 0.65; 'caused': 0.69; 'presented': 0.69; 'url:]': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=E3OXhAFkUOXztxXIeQDxzcBmRnHPebLQVHTbSQ2/Bk4=; b=UEisFR2w67B6gpnLw8o1aKihFnF5vaCCJmJAuXJVo9gaH8IbDZAqQmM7TBTmwAsb5x 7vEBPLnz4ebs14D5n7+LR2mm4PTPPaKaSQiFKXFW/p4i7Fn6KjkLeEQOI65oUxpYUFJP 68y+Ab9lKqLhk+QvWvMfV0pkJ3PGtl/Nk0XKcWZZqENlaVreMtgzixV4oQ4qzPuFjBMF I79LQffqfeIPkT89Q9smVYwK2+jc4M9oSv5nM18NT8h8+sFVAr6j8b/SIRzBWLhomfmn u6GOw3s32TmcJfcwjaWlgiD8Lr4q4ss2dc40kUm/WjM5nfTHXuypkDJdeE2yxQwxjgnI d9Hg==
X-Received by 10.112.42.44 with SMTP id k12mr4286125lbl.63.1372338549699; Thu, 27 Jun 2013 06:09:09 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <51CC35F4.3040609@gmail.com>
References <51CC35F4.3040609@gmail.com>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date Thu, 27 Jun 2013 14:08:29 +0100
Subject Re: Why is the argparse module so inflexible?
To Andrew Berg <robotsondrugs@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc "comp.lang.python" <python-list@python.org>
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.3927.1372338551.3114.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372338551 news.xs4all.nl 15863 [2001:888:2000:d::a6]:54046
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49319

Show key headers only | View raw


On 27 June 2013 13:54, Andrew Berg <robotsondrugs@gmail.com> 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, 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. Overriding ArgumentParser.error doesn't really help since methods like parse_known_args just send a
> message to be relayed to the user as an argument after swallowing ArgumentError (which does have useful information in its attributes). If I
> wanted to figure out what actually caused the exception to be raised, I'd have to parse the message, which is ugly at best. I understand
> that most people do want argparse to just display a message and terminate if the arguments supplied aren't useful, but there's a lot of
> potential in the module that is crippled outside the main use case. I have to wonder why a module that is meant to be imported would ever
> call sys.exit(), even if that is what the caller would normally do if presented with an exception.

>>> import sys
>>> try: sys.exit()
... except SystemExit: pass
...
>>>

That said, you might want to try docopt [http://docopt.org/] if you
have qualms with ArgParse.

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


Thread

Re: Why is the argparse module so inflexible? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-27 14:08 +0100

csiph-web