[ANN] argparse 0.6 - Command-line parsing library

Steven Bethard steven.bethard at gmail.com
Sat Feb 24 19:11:42 CET 2007

Announcing argparse 0.6

argparse home:

argparse single module download:

argparse bundled downloads at PyPI:

About this release

This release adds support for argument groups, and fixes a bug in the
display of required options. Also, the source distribution of this
release should now include the tests.

Note that the 'outfile' type is still deprecated and will likely be
removed in the next release. Please update your code to use the new
FileType factory.

New in this release

* Required options are no longer displayed with brackets (so that they
no longer look optional).

* The source distribution includes ``test_argparse.py``, argparse's
test suite.

* Arguments can now be grouped into user-defined sections instead of
the default "positional arguments" and "optional arguments" sections::

    >>> parser = argparse.ArgumentParser(prog='PROG', add_help=False)
    >>> xgroup = parser.add_argument_group('xxxx')
    >>> xgroup.add_argument('-x', help='x help')
    >>> ygroup = parser.add_argument_group('yyyy')
    >>> ygroup.add_argument('y', help='y help')
    >>> parser.print_help()
    usage: PROG [-x X] y

      -x X  x help

      y     y help

About argparse

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

* handling both optional and positional arguments
* supporting parsers that dispatch to sub-parsers
* producing more informative usage messages
* supporting actions that consume any number of command-line args
* allowing types and actions to be specified with simple callables
instead of hacking class attributes like STORE_ACTIONS or

as well as including a number of other more minor improvements on the
optparse API. To whet your appetite, here's a simple program that sums
its 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))

More information about the Python-announce-list mailing list