Getting into arguments

By Filip Salo; published on February 22, 2007. Tags: python

I've written briefly about command-line argument parsing before.

The standard library has getopt, which implements the classic getopt interface, and optparse, which takes a more object-oriented approach.

I've glanced at Steven Bethard's argparse module before, but I still haven't really tried it out. It seems to be of the fairly powerful kind, yet lacks some features that optparse has (to be fair, it probably does things that optparse doesn't as well).

Now I noticed another argparse, by Sean B. Palmer, which looks kind of nice at least for the simpler use cases (which are the most frequent for me). Here's the usage example from the site:

o = Opts('%prog [options] [<string name>] <string path>')
o.addopt('-c --chmod <int>   chmod a file on the server')
o.addopt('-u --update        update a file, on the server or locally')
o.addopt('-g --get           download a file from the server')
o.addopt('-d --delete        delete a file from the server')
options = o.parse(argv)

I think I'd like a single standard library module that provides three things: The old getpot interface, mostly for historic reasons and for old farts; something very configurable like optparse or Bethard's argparse, and a more "just type it" variant, similar to Palmer's argparse, probably just being a wrapper around the more complex one.

I think that would cover it for most people. You?

Links