[ANN] argparse 0.8 - Command-line parsing library

Steven Bethard steven.bethard at gmail.com
Sun May 27 18:32:21 CEST 2007

Announcing argparse 0.8

The argparse module is an optparse-inspired command line parser that
improves on optparse by supporting:

* positional arguments
* sub-commands
* required options
* options with a variable number of args
* better usage messages
* a much simpler extension mechanism

and a number of other improvements on the optparse API.

Download argparse

argparse home:

argparse single module download:

argparse bundled downloads at PyPI:

Example argparse code

Here's a simple program that sums its the command-line arguments and
writes them to a file::

 parser = argparse.ArgumentParser()
 parser.add_argument('integers', nargs='+', type=int)
 parser.add_argument('--log', default=sys.stdout,
 args = parser.parse_args()
 args.log.write('%s\n' % sum(args.integers))

About this release

This release adds support for options with different prefix
characters, a parser-level default for all arguments, and help
messages for subparser commands.

The deprecated 'outfile' type was finally removed in this release.
Please update your code to use the FileType factory.

New features

* Options with different prefix characters, e.g. ``+foo`` or ``/bar``,
using the new ``prefix_chars=`` keyword argument to ArgumentParser.

* A parser-level argument default using the new ``argument_default=``
keyword argument to ArgumentParser.

* Support for ``help=`` in the ``add_parser()`` method of subparsers.

Bugs fixed

* ``set_defaults()`` now correctly overrides defaults from
``add_argument()`` calls

* ``default=SUPPRESS`` now correctly suppresses the action for
positional arguments with ``nargs='?'`` or ``nargs='*'``.

More information about the Python-announce-list mailing list