1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<%= header 'python.hdr' %>
""" Module Description """
#----------------------------------------------------------------------------
__version__ = '0.1.0'
#----------------------------------------------------------------------------
#import
#----------------------------------------------------------------------------
__all__ = [
'<%= @filename_base %>'
]
#----------------------------------------------------------------------------
class <%= @filename_base %>:
def __init__( self, parser, options ):
self.parser = parser
self.options = options
#----------------------------------------------------------------------------
def my_callback( option, opt, value, parser ):
print "option : %s" % option
print "opt : %s" % opt
print "value : %s" % value
print "parser : %s" % parser
#----------------------------------------------------------------------------
def main( ):
from optparse import OptionParser
parser = OptionParser( usage="usage : %prog [-h] [-v]", version= "%prog version " + __version__ )
# action store store_true store_false store_const append count callback help
# type string int long choice float complex
# dest action="store*"
# default
# nargs int
# const action="store_const"
# choices
# callback
# callback_args
# callback_kwargs
# help help tring
# metavar
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="produces noisy outputs." )
parser.add_option("-c", "--callback", action="callback", callback=my_callback, help="print callback args" )
parser.add_option("-s", "--string", action="store", type="string", dest="string", help="memorize a string" )
( options, args) = parser.parse_args( )
print 'verbose : %s' % options.verbose
return 0
#----------------------------------------------------------------------------
if __name__ == '__main__':
import sys
sys.exit( main( ) )
|