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


Groups > comp.lang.python > #49326

Re: Why is the argparse module so inflexible?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <robotsondrugs@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'essentially': 0.04; 'cpython': 0.05; 'insert': 0.05; 'processing.': 0.07; 'arguments': 0.09; 'override': 0.09; 'parsing': 0.09; 'subject:Why': 0.09; 'subject:module': 0.09; 'windows': 0.15; "'-'": 0.16; 'condensed': 0.16; 'exception;': 0.16; 'mangled': 0.16; 'roy': 0.16; 'sorts': 0.16; 'subject:argparse': 0.16; 'user-defined': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'normally': 0.19; 'things.': 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; 'function': 0.29; 'raise': 0.29; "doesn't": 0.30; "i'm": 0.30; 'code': 0.31; 'probably': 0.32; 'quite': 0.32; 'running': 0.33; 'becomes': 0.33; 'actual': 0.34; 'subject:the': 0.34; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'method': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'easily': 0.37; 'sometimes': 0.38; 'message-id:@gmail.com': 0.38; '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; 'middle': 0.60; 'solve': 0.60; 'simple': 0.61; "you're": 0.61; 'more': 0.64; 'details': 0.65; 'smith': 0.68; 'useful.': 0.68; '9.1': 0.84; 'freebsd': 0.84; 'quits.': 0.84; 'verifying': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=cQDVxP/5WcGRlqw6R0uqBgW8ziiMjifbOZVpxt1SUHM=; b=KZwaF8F12EpI7lr6NzDbdfBE0oF63FToLeOgHKSL9DY1oMaNau64HKmDjTxEmFhXO8 yZ1JQ5nHlCdOTib55QXK5TX7afTFkFtpcd0VQjW/NAVHtXUgxGcz9QidgEyzvin2e3qT gqwfNS2sX3+1nOjFRgBc7fAtEFTMXphPtt9Riq4kXx2drY+khGOdY4guCj73nHjP8I9o phMP496CsSkzjX6GO20yLl32jds38Bt1XxEsKmFaOGsKQuFAABY8hz/I81KWk+AvQshW xzAxAZeMXVuwqX1Zau1HlmPzl+hTcnisYiouic5y7d3MHeNo7RK2Q+PaBBV5tb8ScTpz BfVg==
X-Received by 10.50.62.72 with SMTP id w8mr15794916igr.24.1372341007120; Thu, 27 Jun 2013 06:50:07 -0700 (PDT)
Date Thu, 27 Jun 2013 08:49:23 -0500
From Andrew Berg <robotsondrugs@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
MIME-Version 1.0
To "comp.lang.python" <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>
In-Reply-To <roy-57E318.09080527062013@70-1-84-166.pools.spcsdns.net>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
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.3930.1372341016.3114.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372341016 news.xs4all.nl 15895 [2001:888:2000:d::a6]:55227
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49326

Show key headers only | View raw


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. In this case,
the message gets mangled if error is overridden, and I don't know why.

> You might look into "type=".  It's normally used for things like 
> "type=int" or "type=float", but it could give it any user-defined 
> function as a type and this essentially becomes a hook to insert your 
> own code into the middle of the processing.  Sometimes that can be 
> warped into doing all sorts of useful things.
I don't think that would solve my problem, but it would probably be quite useful.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1

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