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


Groups > comp.lang.python > #49319

Re: Why is the argparse module so inflexible?

References <51CC35F4.3040609@gmail.com>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date 2013-06-27 14:08 +0100
Subject Re: Why is the argparse module so inflexible?
Newsgroups comp.lang.python
Message-ID <mailman.3927.1372338551.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 27 June 2013 13:54, Andrew Berg <robotsondrugs@gmail.com> 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, 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.

>>> import sys
>>> try: sys.exit()
... except SystemExit: pass
...
>>>

That said, you might want to try docopt [http://docopt.org/] if you
have qualms with ArgParse.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Why is the argparse module so inflexible? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-27 14:08 +0100

csiph-web