14.3 optparse -- More powerful command line option parserNew in version 2.3.
Here's an example of using from optparse import OptionParser [...] parser = OptionParser() parser.add_option("-f", "--file", dest="filename", help="write report to FILE", metavar="FILE") parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=True, help="don't print status messages to stdout") (options, args) = parser.parse_args() With these few lines of code, users of your script can now do the ``usual thing'' on the command-line, for example: <yourscript> --file=outfile -q
As it parses the command line, <yourscript> -f outfile --quiet <yourscript> --quiet --file outfile <yourscript> -q -foutfile <yourscript> -qfoutfile Additionally, users can run one of <yourscript> -h <yourscript> --help
and usage: <yourscript> [options] options: -h, --help show this help message and exit -f FILE, --file=FILE write report to FILE -q, --quiet don't print status messages to stdout
where the value of yourscript is determined at runtime (normally
from
See About this document... for information on suggesting changes. |