bx.cookbook.doc_optparse module
- Author:
Simionato
- Date:
April 2004
- Title:
A much simplified interface to optparse.
You should use optionparse in your scripts as follows. First, write a module level docstring containing something like this (this is just an example):
'''usage: %prog files [options]
-d, --delete: delete all files
-e, --erase = ERASE: erase the given file'''
Then write a main program of this kind:
# sketch of a script to delete files:
if __name__=='__main__':
import optionparse
option,args=optionparse.parse(__doc__)
if not args and not option: optionparse.exit()
elif option.delete: print "Delete all files"
elif option.erase: print "Delete the given file"
Notice that optionparse
parses the docstring by looking at the
characters “,”, “:”, “=”, “n”, so be careful in using them. If
the docstring is not correctly formatted you will get a SyntaxError
or worse, the script will not work as expected.
- bx.cookbook.doc_optparse.exception(msg='')
- bx.cookbook.doc_optparse.exit(msg='')
- bx.cookbook.doc_optparse.help_callback(option, opt, value, parser, help)
- bx.cookbook.doc_optparse.nonzero(self)
True if options were given
- bx.cookbook.doc_optparse.parse(docstring, arglist=None)