[Python-Dev] PEP 389: argparse - new command line parsing module

Steven Bethard steven.bethard at gmail.com
Tue Sep 29 07:22:26 CEST 2009

On Mon, Sep 28, 2009 at 8:44 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>> Let's take ``getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])``
> As Yuvgoog Greenle says, the canonical getopt way is to write
[snip getopt code]
> Even though this is many more lines, I prefer it over
> optparse/argparse: this code has only a single function call,
> whereas the argparse version has three function calls to remember.
> The actual processing uses standard Python data structures which
> I don't need to look up in the documentation.
>> Now, Steven, can you show how best to do this in argparse?
> This demonstrates my point: you were able to use getopt right away
> (even though not in the traditional way), whereas you need to ask
> for help on using argparse properly.

I don't think this is fair at all. I am totally unable to write getopt
code without checking the documentation -- I don't remember the format
string syntax, nor what the function returns. But that's just how
library modules work -- if you don't know the library, you have to
read the documentation. The only reason getopt is easier for you is
that you're already familiar with the API from C. That said, I can
certainly understand that folks who use getopt in C would have an easy
transition to getopt in Python and a harder transition to argparse.

You didn't directly answer my question of whether adding an
"add_getopt_arguments" function would meet your needs, but I infer
from your answer above that it wouldn't because you'd still need to
make multiple function calls which is your primary complaint. So at
this point, I think it's clear that there's nothing I can reasonably
add to argparse to make getopt people more comfortable that isn't just
duplicating what's already in getopt.

So let's just deprecate optparse (as in the PEP), and leave getopt
alone (other than adding a note to the documentation suggesting
argparse as an alternative).
Where did you get that preposterous hypothesis?
Did Steve tell you that?
        --- The Hiphopopotamus

More information about the Python-Dev mailing list