-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.args.4.for.server.0.py
57 lines (45 loc) · 2.03 KB
/
test.args.4.for.server.0.py
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
import argparse
# https://pymotw.com/2/argparse/
parser = argparse.ArgumentParser()
parser.add_argument('-s', action='store', dest='simple_value',
help='Store a simple value')
parser.add_argument('-c', action='store_const', dest='constant_value',
const='value-to-store',
help='Store a constant value')
parser.add_argument('-t', action='store_true', default=False,
dest='boolean_switch',
help='Set a switch to true')
parser.add_argument('-f', action='store_false', default=False,
dest='boolean_switch',
help='Set a switch to false')
parser.add_argument('-a', action='append', dest='collection',
default=[],
help='Add repeated values to a list',
)
parser.add_argument('-u', action='append', dest='collection_urls',
default=[],
help='Add repeated values to a list',
)
parser.add_argument('-p', action='append', dest='collection_files',
default=[],
help='Add repeated values to a list',
)
parser.add_argument('-A', action='append_const', dest='const_collection',
const='value-1-to-append',
default=[],
help='Add different values to list')
parser.add_argument('-B', action='append_const', dest='const_collection',
const='value-2-to-append',
help='Add different values to list')
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
results = parser.parse_args()
print('simple_value =', results.simple_value)
myurl = results.simple_value
print(type(myurl))
print('constant_value =', results.constant_value)
print('boolean_switch =', results.boolean_switch)
print('collection =', results.collection)
for gg in results.collection_urls:
print("URL",gg)
pass
print('const_collection =', results.const_collection)