[Python-Dev] argparse ugliness

Nick Coghlan ncoghlan at gmail.com
Wed Mar 10 13:46:14 CET 2010

Greg Ewing wrote:
> Steven Bethard wrote:
>> Because the names are so long and you'd have to import them, I've left
>> them as private attributes of the module, but if there's really
>> demand, we could rename them to argparse.StoreTrueAction, etc.
> What's wrong with just StoreTrue?

All of this discussion about the class names is ignoring the main
benefit of using the string names:

- with Python variables, you just get a generic name error at the
reference site (which may or may not be useful, depending on the program
- with a string, the parser *tells* you that the problem is with the
requested action for a particular argument

The second, explicit error is going to be more informative in most cases.

Using strings also reduces the verbosity of the code, avoiding either an
"argparse." buried in the middle of the function call, or else a "from
argparse import <whatever>".


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list