-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs_test.py
More file actions
31 lines (24 loc) · 996 Bytes
/
args_test.py
File metadata and controls
31 lines (24 loc) · 996 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
import argparse
import sys
def parse_argv():
parser = argparse.ArgumentParser(description='test for argparse')
parser.add_argument(dest='filenames', metavar='filenames', nargs='*')
parser.add_argument('-p', '--pat', metavar='pattern', required=True,
dest='patterns', action='append',
help='text pattern to search for')
parser.add_argument('-v', dest='verbose', action='store_true',
help='verbose mode')
parser.add_argument('-o', dest='outfile', action='store',
help='output file')
parser.add_argument('--speed', dest='speed', action='store',
choices=('slow', 'fast'), default='slow',
help='search speed')
args = parser.parse_args()
print(args.filenames)
print(args.patterns)
print(args.verbose)
print(args.outfile)
print(args.speed)
if __name__ == '__main__':
print(sys.argv)
parse_argv()