[ create a new paste ] login | about

Link: http://codepad.org/vq3cvE13    [ raw code | output | fork ]

Python, pasted on Jul 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import optparse

def store_test(option, opt_str, value, parser, args=None, kwargs=None):
    print 'opt_str:', opt_str
    print 'value:', value

op = optparse.OptionParser()
op.add_option('-t', '--test', action='callback', callback=store_test, default='test', 
    dest='test', help='test!')

(opts, args) = op.parse_args(['test.py', '-t', 'foo'])

print
print 'opts:'
print opts
print 'args:'
print args


Output:
1
2
3
4
5
6
7
opt_str: -t
value: None

opts:
{'test': 'test'}
args:
['test.py', 'foo']


Create a new paste based on this one


Comments: