OptionParser How to: prog <cmd> [options] [arguments]
Carl Banks
pavlovevidence at gmail.com
Fri Aug 14 05:38:28 EDT 2009
On Aug 14, 12:18 am, Javier Collado <javier.coll... at gmail.com> wrote:
> 2009/8/14 Steven Woody <narkewo... at gmail.com>:
>
> > Hi,
> > I am using OptionParser, but I've not managed figure out a way to support
> > what I wanted command line format "prog <cmd> [options] [arguments]".
> > E.g., "svn ls -r123http://hello.world". Can I do this using OptionParser?
> > Thanks.
>
> Hello,
>
> I think that this isn't possible with optparse library.
It's possible if you remove sys.argv[1] before invoking optparse.
But...
> However, it's possible with argparse (http://code.google.com/p/argparse/):
> http://argparse.googlecode.com/svn/trunk/doc/other-methods.html#sub-c...
>
> It's not a standard library, but it's worth to take a look at it.
It's more than worth looking at, it's a slam dunk. It's superior to
optparse in every way I can think of. Unless you don't want the third-
party dependency there is no reason to use optparse instead of
argparse.
Carl Banks
More information about the Python-list
mailing list