Module optionparser
:Original Author: Russ Cox <rsc@plan9.bell-labs.com>
:Modified By: M. George Hansen <technopolitica@gmail.com>
Usage:
------
>>> import sys
>>> usagemessage=... '''usage: example.py [-h] [-f FILE] [-n N] [-q] who where
... -h, --help show this help message
... -f FILE, --file=FILE write report to FILE
... -n N, --num=N print N copies of the report
... -q, --quiet don't print status messages to stdout
... '''
>>> def main():
... opt = OptionParser(usage=usagemessage)
... report = 'default.file'
... ncopies = 1
... verbose = 1
... for o in opt:
... if o=='-f' or o=='--file':
... report = opt.optarg()
... elif o=='-n' or o=='--num':
... ncopies = opt.optarg(opt.typecast(int, 'integer'))
... elif o=='-q' or o=='--quiet':
... verbose = 0
... else:
... opt.error('unknown option '+o)
... if len(opt.args()) != 2:
... opt.error('incorrect argument count')
... print 'report=%s, ncopies=%s verbose=%s' % (report, ncopies, verbose)
... print 'arguments: ', opt.args()
...
|
|
__package__ = 'scripts.common'
|