[ANN] The argparse module

Discussion in 'Python' started by Steven Bethard, Aug 3, 2006.

  1. 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
     
    Steven Bethard, Aug 3, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Berg
    Replies:
    17
    Views:
    168
    Ethan Furman
    Jun 29, 2013
  2. Joshua Landau
    Replies:
    0
    Views:
    91
    Joshua Landau
    Jun 27, 2013
  3. Terry Reedy
    Replies:
    0
    Views:
    89
    Terry Reedy
    Jun 27, 2013
  4. Dave Angel
    Replies:
    0
    Views:
    101
    Dave Angel
    Jun 27, 2013
  5. Terry Reedy
    Replies:
    0
    Views:
    103
    Terry Reedy
    Jun 27, 2013
Loading...

Share This Page