optparse

rick rickzolun1 at charter.net
Wed Sep 27 00:29:14 EDT 2006


Consider the following piece of code:

parser = optparse.OptionParser(usage="usage: %prog <input filename> 
<output filename> [options]", add_help_option=False)
parser.add_option("-d", type="string", action="store", dest="DELIM", 
default="|", help="single character delimiter in quotes (default: |)")
(options, args) = parser.parse_args()


Is there any way I can add help for the arguments (<input filename> and 
<output filename>) in the same table that optparse generates above the 
options section. Ideally, I would like the output as:

======================================================
usage: DelimTOFixedWidth.py <input filename> <output filename> [options]

required:
  input filename     name of the delimited input file
  output filename   name of fixed-width output file

options:
  -d DELIM  single character delimiter in quotes (default: |)
======================================================

Is that possible using optparse?

Thanks.



More information about the Python-list mailing list