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

Nick Coghlan ncoghlan at gmail.com
Wed Apr 21 15:48:48 CEST 2010


Tobias Herp wrote:
> 
> What /is/ this ambiguity of the "version=" argument? There is none!
> 
> Do it the way optparse does it, and all is fine!

All is not fine.

How do I add a "-V" shortcut that is equivalent to "--version" as part
of an optparse program? (That's a real question, I honestly have no idea
how I would do that short of writing my own version display option).

Since argparse now uses action='version' instead, the same question
becomes trivial (just list "-V" as one of the accepted options for that
action).

There are at least three reasonable approaches for version options
(ignoring the fact that Windows users expect their options to start with
a '/' instead of a '-'):
   - just "--version" (the optparse way)
   - "-V" and "--version" (the Python interpreter way)
   - "-v" and "--version" (the old argparse way)

The third is by far the least common of the three, but even you admit
both of the first two are quite common and acceptable according to the
de facto "standard".

Optparse makes it easy to do it the optparse way, but difficult to
support either of the other formats. Argparse used to be in a similar
boat, where only the third option was easy.

The latest argparse approach is straightforward regardless of the
particular spelling you happen to prefer. Since getting away from the
"thou shalt" preachiness of optparse is one of the big reasons for
adding argparse in the first place, it seems odd to complain when it
switches to a more consistent and flexible API.

There were a couple of issues to be addressed with the implementation
and the documentation, but the basic approach is sound.

Cheers,
Nick.

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


More information about the Python-Dev mailing list