Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49319 > unrolled thread
| Started by | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| First post | 2013-06-27 14:08 +0100 |
| Last post | 2013-06-27 14:08 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Why is the argparse module so inflexible? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-27 14:08 +0100
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| Date | 2013-06-27 14:08 +0100 |
| Subject | Re: Why is the argparse module so inflexible? |
| Message-ID | <mailman.3927.1372338551.3114.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web