On Sep 30, 2009, at 11:39 AM, Steven Bethard wrote:

Thanks for the clarification. I generally like this approach, though
it's not so convenient for argparse which already takes format strings
like this::

   parser = ArgumentParser(usage='%(prog)s [--foo]')
   parser.add_argument(
       '--foo', type=int, default=42,
       help='A foo of type %(type)s, defaulting to %(42)s)

That is, existing keyword arguments that already have good names (and
are pretty much always used as keyword arguments) take format strings.
I'm not sure that changing the name of usage= or help= here is really
an option.

Ah right.

I guess in this case I'm stuck with something like Benjamin's
suggestion of adding an additional flag to control which type of
formatting, and the corresponding 4 versions of cleanup. Ew.

I missed Benjamin's suggestion, but in this case I would say add a flag to ArgumentParser. I'm either going to want {} formatting all or nothing. E.g.

import argparse
parser = ArgumentParser(usage='{prog} [--foo]', format=argparse.BRACES)
parser.add_argument(
    '--foo', type=int, default=42,
    help='A foo of type {type}, defaulting to {42}')

(although that last looks weird ;).

-Barry

Attachment: PGP.sig
Description: This is a digitally signed message part

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to