[Python-Dev] argparse ugliness

Ben Finney ben+python at benfinney.id.au
Mon Mar 8 22:55:50 CET 2010


David Stanek <dstanek at dstanek.com> writes:

> On Mon, Mar 8, 2010 at 10:40 AM, Steven Bethard
> <steven.bethard at gmail.com> wrote:
> >  parser.add_argument ('--plot', action='store_true')
[…]

+1.

> Any reason not to do something like:
>
>   from argparse import actions
>   ...
>   parser.add_argument('--plot', actions.store_true)
>
> Basically a small namespace for the constants.

-1.

That ignores the value to the programmer in specifying keyword arguments
(there are a lot of arguments to the function, making keyword arguments
a better mean-what-you-say choice). To be equivalent, it would have to
be:

    from argparse import actions
    # ...

    parser.add_argument('--plot', action=actions.store_true)

I prefer the string values.

-- 
 \           “Value your freedom or you will lose it, teaches history. |
  `\     “Don't bother us with politics,” respond those who don't want |
_o__)                               to learn.” —Richard Stallman, 2002 |
Ben Finney



More information about the Python-Dev mailing list