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


Groups > comp.lang.python > #49334

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!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'arguments': 0.09; 'exception,': 0.09; 'exception.': 0.09; 'override': 0.09; 'parsing': 0.09; 'raises': 0.09; 'subject:Why': 0.09; 'subject:module': 0.09; "'-'": 0.16; 'condensed': 0.16; 'exception;': 0.16; 'mangled': 0.16; 'roy': 0.16; 'subject:argparse': 0.16; 'systemexit': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'pointed': 0.19; 'written': 0.21; 'input': 0.22; 'example': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'why.': 0.24; "i've": 0.25; 'class.': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'raise': 0.29; "doesn't": 0.30; 'andrew': 0.30; "i'm": 0.30; 'code': 0.31; 'there.': 0.32; 'running': 0.33; 'actual': 0.34; 'subject:the': 0.34; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'case,': 0.35; 'no,': 0.35; 'but': 0.35; 'method': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'clear': 0.37; 'easily': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'short': 0.38; 'does': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'catch': 0.60; 'simple': 0.61; "you're": 0.61; 'more': 0.64; 'details': 0.65; 'received:74.208': 0.68; 'smith': 0.68; 'quits.': 0.84; 'received:74.208.4.194': 0.84; 'verifying': 0.84
Date Thu, 27 Jun 2013 12:02:22 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6
MIME-Version 1.0
To python-list@python.org
Subject Re: Why is the argparse module so inflexible?
References <mailman.3924.1372337705.3114.python-list@python.org> <roy-57E318.09080527062013@70-1-84-166.pools.spcsdns.net> <51CC42E3.3070508@gmail.com>
In-Reply-To <51CC42E3.3070508@gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:NPLmoDSpxntoE4VivhpyHkox+Uganqab1W6fbAol2GA vFCBGJJFkN/GchlZcNCVO2jesDh7s51pUc4lw17ncBDso7/Im5 bENzgFRotndtXHZVln/TPY24xd8QwyFTfMKLdZdey1qw4SlAjr dCxhMg2YscWULA+YSYtW59p7ddWdww6bqwE08GWJtO41qnkYKR Dibrh/HHqcqGN93usskgdbXQuaWGzanbbGlP3BFEqimgC7l729 kbkpwgZ8Irrvt/xFkFlms6z5I54HOydRkYyvoely35xMezVVVv 3mKQuYHgQJJpwc1GJs7Wy434r0//8syFVbN+LzHw7WfbCV0fVw myvfStHDgd/QaB7Bq5nk=
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.3933.1372348963.3114.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372348963 news.xs4all.nl 15914 [2001:888:2000:d::a6]:51921
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49334

Show key headers only | View raw


On 06/27/2013 09:49 AM, Andrew Berg wrote:
> On 2013.06.27 08:08, Roy Smith wrote:
>> Can you give us a concrete example of what you're trying to do?
> The actual code I've written so far isn't easily condensed into a short simple snippet.
> I'm trying to use argparse to handle all the little details of parsing and verifying arguments in the precmd hook for a cmd.Cmd child class.
> argparse's help system is more sophisticated than cmd's help and does all the work of verifying arguments.
> The problem I keep running into is that I can't handle any bad input very well. I would have to override every method that catches
> ArgumentError in order to get a useful exception that I would then handle.
> If I input something that begins with '-' that isn't recognized, parse_args doesn't even raise the exception; it just quits.

No, it raises the SystemExit exception.  if you don't catch it, then the 
program exits.  Perhaps it's not clear to you, but sys.exit() just 
raises the SystemExit exception, as  Joshua pointed out.

> In this case,
> the message gets mangled if error is overridden, and I don't know why.
>

I can't help there.


-- 
DaveA

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


Thread

Why is the argparse module so inflexible? Andrew Berg <robotsondrugs@gmail.com> - 2013-06-27 07:54 -0500
  Re: Why is the argparse module so inflexible? Roy Smith <roy@panix.com> - 2013-06-27 09:08 -0400
    Re: Why is the argparse module so inflexible? Andrew Berg <robotsondrugs@gmail.com> - 2013-06-27 08:49 -0500
    Re: Why is the argparse module so inflexible? Dave Angel <davea@davea.name> - 2013-06-27 12:02 -0400
      Re: Why is the argparse module so inflexible? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-27 22:49 +0000
        Re: Why is the argparse module so inflexible? Cameron Simpson <cs@zip.com.au> - 2013-06-28 09:34 +1000
        Re: Why is the argparse module so inflexible? Ethan Furman <ethan@stoneleaf.us> - 2013-06-28 18:36 -0700
          Re: Why is the argparse module so inflexible? rusi <rustompmody@gmail.com> - 2013-06-28 21:12 -0700
            Re: Why is the argparse module so inflexible? Terry Reedy <tjreedy@udel.edu> - 2013-06-29 00:37 -0400
              Re: Why is the argparse module so inflexible? Roy Smith <roy@panix.com> - 2013-06-29 10:12 -0400
                Re: Why is the argparse module so inflexible? Andrew Berg <robotsondrugs@gmail.com> - 2013-06-29 09:17 -0500
          Re: Why is the argparse module so inflexible? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-29 05:28 +0000
            Re: Why is the argparse module so inflexible? Marcin Szamotulski <mszamot@gmail.com> - 2013-06-29 13:38 +0100
            Re: Why is the argparse module so inflexible? MRAB <python@mrabarnett.plus.com> - 2013-06-29 16:58 +0100
            Re: Why is the argparse module so inflexible? Ethan Furman <ethan@stoneleaf.us> - 2013-06-29 12:17 -0700
        Re: Why is the argparse module so inflexible? Modulok <modulok@gmail.com> - 2013-06-28 19:39 -0600
        Re: Why is the argparse module so inflexible? Isaac To <isaac.to@gmail.com> - 2013-06-29 12:37 +0800
    Re: Why is the argparse module so inflexible? Robert Kern <robert.kern@gmail.com> - 2013-06-27 20:47 +0100

csiph-web