Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!nuzba.szn.dk!pnx.dk!news.stupi.se!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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'cpython': 0.05; '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; 'useful,': 0.14; 'windows': 0.15; 'attributes).': 0.16; 'letting': 0.16; 'overriding': 0.16; 'raised,': 0.16; 'subject:argparse': 0.16; 'supplied': 0.16; 'exception': 0.16; 'module': 0.19; 'normally': 0.19; 'user.': 0.19; 'meant': 0.20; 'input': 0.22; 'header:User- Agent:1': 0.23; "aren't": 0.24; 'case.': 0.24; 'parse': 0.24; "i've": 0.25; 'wonder': 0.29; "doesn't": 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; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'message-id:@gmail.com': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'skip:u 10': 0.60; 'most': 0.60; 'information': 0.63; 'great': 0.65; 'caused': 0.69; 'presented': 0.69; '9.1': 0.84; 'freebsd': 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 :content-type:content-transfer-encoding; bh=wfchyv3fnGLxM0xI5Sk9pQsurmJbQesvAAc5URA2p+A=; b=p2+cNKnCpwlGLxxp7jdbS+jNMEJQBx6JdbeLZy+hmW9f2EzpELepMs6n1eClYlIDrh fcD4IEIPMjl2RruqCPOOrKaTIKSc49Yiwxd4Q/TJlUt/xyvNnQkbFJD479N78MPVAi64 kwXM5vm1/E+zJmm9hAqnbGQ7kjj3XL44BZr0N49q8FItd1Ivd1+dVHjXEQbN3CrRpsdp jTz5WwlO7NDHpUWQmPveJ+H9++Ii2mmnxWirZTIJhwlqfO+QaZffe+t2UTH2+gBfNl8L l/X4Nq7s84eW0I5jP0yS3F4CPrp1pENw+l1nxzpMeagJ+6Q846GbXsHP/lPMGmJRzLT4 XDOg== X-Received: by 10.50.21.70 with SMTP id t6mr15568096ige.36.1372337696012; Thu, 27 Jun 2013 05:54:56 -0700 (PDT) Date: Thu, 27 Jun 2013 07:54:12 -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: Why is the argparse module so inflexible? 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: 10 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372337705 news.xs4all.nl 15962 [2001:888:2000:d::a6]:45319 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49315 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. -- CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1