[Python-Dev] Python 2.7b1 and argparse's version action

Ron Adam rrr at ronadam.com
Mon Apr 19 06:05:41 CEST 2010



On 04/18/2010 06:35 PM, Nick Coghlan wrote:
> Steven Bethard wrote:
>> On Sun, Apr 18, 2010 at 3:57 PM, Nick Coghlan<ncoghlan at gmail.com>  wrote:
>>> Steven Bethard wrote:
>>>> By the way, we could simplify the typical add_argument usage by adding
>>>> "show program's version number and exit" as the default help for the
>>>> 'version' action. Then you should just write:
>>>>
>>>>      parser.add_argument('--version', action='version', version='<the version>')
>>> With that change, I would have no problem with the current argparse
>>> behaviour (since doing it this way makes it very easy for people to add
>>> a "-V" shortcut if they want one).
>>
>> Probably this should happen regardless of the outcome of the
>> constructor argument. The only reason it wasn't already there is that
>> I hadn't thought of it. ;-)
>
> Crazy thought... would it make sense to have the following implicitly
> use "--version" as the option flag:
>
>    parser.add_argument(action='version', version='<details>')
>
> There are two things about the explicit '--version' that bother me:
> 1. It reduces the automatic provision of "standard" option spellings

I think any non standard spellings will either be on purpose or be caught 
fairly quickly.  And in either case I can't imagine it having an impact on 
the rest of the program, so I wouldn't worry about this too much.


> 2. The repetition in reading/writing 'version' 3 times is kind of annoying

Ahh, but it isn't the same exact 'version' each time.  One is an input 
specifier string, one is an action key, and the last is a value name.


> (Probably a bad idea, since adding "-V" would mean having to add
> "--version" as well, but figured it was worth mentioning).

I agree. Even though it may seem redundant when writing it, it's both clear 
and explicit when reading it even if you aren't very familiar with how 
argparse works, or have just returned from a really long and fun vacation. ;-)

Ron







More information about the Python-Dev mailing list