-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdopt_test_alt.py
More file actions
46 lines (27 loc) · 1010 Bytes
/
cmdopt_test_alt.py
File metadata and controls
46 lines (27 loc) · 1010 Bytes
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
import sys
import cmdopt
## print cmdopt.options
# print sys.argv
# print cmdopt.options.count()
def get_option( dic, key, default = None ) :
""" check for "--key" and '-key[0]' """
ret = dic[key]
if ret is None : ret = dic[ key[0] ]
if ret is None : ret = default
return ret
cmdopt.options.__class__.get_option = get_option
## options = cmdopt.options
options = cmdopt.string_options
print "raw values:", options
# if cmdopt.options['o'] is None and options['option'] is None:
if options.get_option('option') is None:
print " neither '-o' nor '--option' keys were specified ! "
#
# testing the convert() method:
#
conv_table = { "i,int" : int
, "f,float" : float
# custom stuff
, "custom" : lambda x: int(x[2:],16) if x.startswith('0x') else int(x)
}
print "converted values:", options.convert( conv_table )