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: 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 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" Subject: Re: Why is the argparse module so inflexible? References: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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