[ANN] The argparse module

S

Steven Bethard

I'm pleased to announce initial availability of the argparse module,
an optparse-inspired command line parser:

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

The argparse module can be downloaded as a single file, argparse.py,
through the Browse Source link on the website.

Argparse improves on optparse by:

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

as well a number of other improvements on the optparse API.

Just to whet your appetite:
parser = argparse.ArgumentParser(prog='PROG')
_ = parser.add_argument('--foo', type=int, choices=[1, 2, 3], .... help='optional with integer choices')
_ = parser.add_argument('--bar', nargs='?', const='C', default='D', .... help='optional with or without arg')
_ = parser.add_argument('baz', nargs='+', type=float, .... help='positional with one or more args')
parser.parse_args('--bar --foo 2 0.5 1.5'.split())
Namespace(bar='C', baz=[0.5, 1.5], foo=2)

This is the first public presentation of this module, so the APIs are
still subject to change. If you find it of interest, and you'd like to
help improve it, I'd be glad to open the project up to more
developers.

Bug reports can be made through Trac at:
http://argparse.python-hosting.com/newticket


Steven Bethard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top