Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string': 0.09; 'arguments': 0.09; 'parsers': 0.09; 'parsing': 0.09; 'propagate': 0.09; 'required,': 0.09; 'sentence': 0.09; 'subject:Why': 0.09; 'subject:module': 0.09; 'abort': 0.16; 'letting': 0.16; 'non- default': 0.16; 'reasonable.': 0.16; 'reedy': 0.16; 'subject:argparse': 0.16; 'systemexit': 0.16; 'exception': 0.16; 'so.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'module': 0.19; 'user.': 0.19; 'command': 0.22; 'input': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'parse': 0.24; 'passes': 0.24; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'andrew': 0.30; 'returned': 0.30; 'that.': 0.31; 'catching': 0.31; 'context.': 0.31; 'restricted': 0.31; "user's": 0.31; 'probably': 0.32; 'another': 0.32; 'quite': 0.32; 'trouble': 0.34; 'sense': 0.34; 'subject:the': 0.34; 'something': 0.35; 'usual': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'subject:?': 0.36; 'should': 0.36; 'application': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'above,': 0.60; 'tell': 0.60; 'great': 0.65; 'received:74.208': 0.68; 'blow': 0.84; 'circuit': 0.84; 'dsl': 0.84; 'nonsense.': 0.84; 'received:74.208.4.194': 0.84 Date: Thu, 27 Jun 2013 14:18:45 -0400 From: Dave Angel 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: <51CC35F4.3040609@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:Uy97D3xTJXqCHJCGZqfuFKZg7lFtRoCEggn4uRqwKFY NTdI3UMXV5wbEgq3hyydaxObcH9sNhigEOnISXQ6C0KVNijLxP FpbBfamIw8UtE3V11H5rxJP03eAZn8DWS82aqbMqTNQDtTaPEQ gyJRN8m5HX7DYDNglmIdeYBocJnync+0E33pMk0rpDjh3svQ1h Rkg3nkae2dWWagjY1PMlZQ8r9cT99XfV1BmHwzehb061KligUC zI7pyqtc5FUaYFc5ptkDun1kk7A9yaCc3GY2RZaqsNF2E/9B8s K1tdKONRzmeK62c3yeg2HmQyMmcqbdqI29IU05V/59u5oG31Zf xyEKe60DXt3X4c7bW3Ok= 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372357142 news.xs4all.nl 15961 [2001:888:2000:d::a6]:51073 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49342 On 06/27/2013 02:05 PM, Terry Reedy wrote: > On 6/27/2013 8:54 AM, Andrew Berg 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, > > It is outside argparse's intended domain of application -- parsing > command line arguments. The grammar for a valid string of command line > arguments is quite restricted. > > Argparse is not intended for interactive processing of a domain-specific > language (DSL). There are other parsers for that. But if the grammar for > your DSL is restricted to what argparse can handle, using it is an > interesting idea. But you need non-default usage for the non-default > context. > > > 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. > > When one tell argparse that something is *required*, that means "I do > not want to see the user's input unless it passes this condition." After > seeing an error message, the user can edit the command line and re-enter. > > If you do not mean 'required' in the sense above, do not say so. > Catching SystemExit is another way to say 'I did not really mean > required, in the usual mean of that term.'. > That last sentence is nonsense. If one is parsing the line the user enters via raw_input(), catching SystemExit so the program doesn't abort is perfectly reasonable. The user should be returned to his prompt, which in this case is probably another loop through raw_input(). Or perhaps entering a bad password should blow the circuit breaker? -- DaveA