Software: Apache/2.0.54 (Unix) mod_perl/1.99_09 Perl/v5.8.0 mod_ssl/2.0.54 OpenSSL/0.9.7l DAV/2 FrontPage/5.0.2.2635 PHP/4.4.0 mod_gzip/2.0.26.1a uname -a: Linux snow.he.net 4.4.276-v2-mono-1 #1 SMP Wed Jul 21 11:21:17 PDT 2021 i686 uid=99(nobody) gid=98(nobody) groups=98(nobody) Safe-mode: OFF (not secure) /opt/doc/python-2.3.4/html/Python-Docs-2.3.4/lib/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 6.20 optparse -- Powerful parser for command line options.
New in version 2.3. The optparse module is a powerful, flexible, extensible, easy-to-use command-line parsing library for Python. Using optparse, you can add intelligent, sophisticated handling of command-line options to your scripts with very little overhead. Here's an example of using optparse to add some command-line options to a simple script:
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:
$ <yourscript> -f outfile --quiet $ <yourscript> -qfoutfile $ <yourscript> --file=outfile -q $ <yourscript> --quiet --file outfile
(All of these result in Even niftier, users can run one of $ <yourscript> -h $ <yourscript> --help
usage: <yourscript> [options] options: -h, --help show this help message and exit -fFILE, --file=FILE write report to FILE -q, --quiet don't print status messages to stdout That's just a taste of the flexibility optparse gives you in parsing your command-line.
See About this document... for information on suggesting changes. |
:: Command execute :: | |
--[ c99shell v. 1.0 pre-release build #13 powered by Captain Crunch Security Team | http://ccteam.ru | Generation time: 0.0045 ]-- |