Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49341
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Why is the argparse module so inflexible? |
| Date | 2013-06-27 14:05 -0400 |
| References | <51CC35F4.3040609@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3936.1372356326.3114.python-list@python.org> (permalink) |
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.'. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Why is the argparse module so inflexible? Terry Reedy <tjreedy@udel.edu> - 2013-06-27 14:05 -0400
csiph-web