[Python-Dev] Pronouncement on PEP 389: argparse?

Steven Bethard steven.bethard at gmail.com
Tue Dec 15 02:54:33 CET 2009


On Mon, Dec 14, 2009 at 4:16 PM, ssteinerX at gmail.com
<ssteinerx at gmail.com> wrote:
>
> On Dec 14, 2009, at 2:37 PM, Antoine Pitrou wrote:
>
>> Michael Foord <fuzzyman <at> voidspace.org.uk> writes:
>>>
>>> I also use -v for verbose in a few scripts (including options to
>>> unittest when run with python -m). I've seen -V as a common abbreviation
>>> for --version (I've just used this with Mono for example).
>>
>> +1 for letting -v mean "--verbose". This is a really common wish.
>
> +1, -v == --verbose

Because people are continuing this discussion, I'll say again that
argparse already supports this:

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-v', '--verbose', action='store_true')
>>> parser.parse_args(['-v'])
Namespace(verbose=True)

If you want to also have a -V/--version argument, you can do that too:

>>> parser.add_argument('-V', '--version', action='version', version='3.5')
>>> parser.parse_args(['-V'])
3.5

And now back to our regularly scheduled discussion of actual PEP issues. ;-)

Steve
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
        --- The Hiphopopotamus


More information about the Python-Dev mailing list