Why is the argparse module so inflexible?

Cameron Simpson cs at zip.com.au
Thu Jun 27 19:02:13 EDT 2013


On 27Jun2013 11:50, Ethan Furman <ethan at stoneleaf.us> wrote:
| If the OP is writing an interactive shell, shouldn't `cmd` be used
| instead of `argparse`?  argparse is, after all, intended for
| argument parsing of command line scripts, not for interactive work.

This is specious.

I invoke command line scripts interactively. There's no special case here.

If argparse is raising a useful and inspectable bad argument
exception, why not let it out? Catching that argument and wrapping
it in something opaque seems unhelpful.  After all, if the caller
really wanted to abort on bad arguments the caller would simply not
catch that exception.  There's no need to transmute it into a
whole-program abort.

If Terry's assertion is that the OP has told argparse he never wants
to see bad input, how does one turn that off?

To add to the use case stats, I also subclass cmd and parse interactive
command lines. I'm beginning to be pleased I'm still using Getopt
for that instead of feeling I'm lagging behind the times.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

If it can't be turned off, it's not a feature. - Karl Heuer



More information about the Python-list mailing list