[ANN] argparse 0.2 - Command-line parsing library

Steven Bethard steven.bethard at gmail.com
Tue Oct 24 01:36:48 CEST 2006


Announcing argparse 0.2
-----------------------

argparse home:
 http://argparse.python-hosting.com/

argparse single module download:
 http://argparse.python-hosting.com/file/trunk/argparse.py?format=raw

argparse bundled downloads at PyPI:
 http://www.python.org/pypi/argparse/


About this release
==================

This release fixes a few minor bugs, modifies the 'store_true' and
'store_false' actions to have more natural defaults, and adds an
epilog= keyword argument to ArgumentParser for text to be printed
after the help messages. (The latter is in line with the `updates to
optparse`_ for Python 2.5.)

.. _updates to optparse: http://www.python.org/doc/2.5/whatsnew/modules.html

New in this release
===================

* The 'store_true' action's default is now False (instead of None).
* The 'store_false' action's default is now True (instead of None).
* ArgumentParser objects now accept an epilog= keyword argument.


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
CHECK_METHODS

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', type=int, nargs='+')
   parser.add_argument('--log', type='outfile', default=sys.stdout)
   args = parser.parse_args()
   args.log.write('%s\n' % sum(args.integers))
   args.log.close()


More information about the Python-announce-list mailing list