argparse 1.0 - Command-line parsing library

Steven Bethard steven.bethard at gmail.com
Sun Jul 26 19:14:02 CEST 2009


=======================
Announcing argparse 1.0
=======================
The argparse module provides an easy, declarative interface for
creating command line tools, which knows how to:
 * parse the arguments and flags from sys.argv
 * convert arg strings into objects for your program
 * format and print informative help messages
 * and much more...

The argparse module improves on the standard library optparse module
in a number of ways including:
 * handling positional arguments
 * supporting sub-commands
 * allowing alternative option prefixes like + and /
 * handling zero-or-more and one-or-more style arguments
 * producing more informative usage messages
 * providing a much simpler interface for custom types and actions

Download argparse
=================
The argparse homepage has links for source, MSI and single file
distributions of argparse:
  http://code.google.com/p/argparse/

About this release
==================
This release includes a number of new features:

* Support for Python versions 2.3 through 3.1. No need to run 2to3 or
  anything like that -- the argparse source code is both fully 2.X
  and 3.X compatible.

* ``ArgumentParser`` grew a ``parse_known_args`` method which works
  like ``parse_args`` but collects unrecognized arguments into a list
  instead of raising an exception

* The ``ArgumentParser`` constructor accepts a new parameter for
  reading additional arguments from files. For example,
  ``fromfile_prefix_chars='@'`` means that arguments like ``@file``
  should be replaced by the arguments read from the given file.

* A new formatter class, ``ArgumentsDefaultHelpFormatter`` is
  available, which will automatically add ``(default: %(default)s)``
  to all argument help messages

* The ``metavar`` parameter to ``add_argument`` now accepts a tuple
  of strings in additional to a single string so that more than one
  name can be specified.

* The ``add_subparsers`` method now accepts ``title`` and
  ``description`` parameters which will cause it to display like an
  argument group in help messages.


More information about the Python-announce-list mailing list