-
Notifications
You must be signed in to change notification settings - Fork 2
/
py_template
executable file
·48 lines (38 loc) · 1.34 KB
/
py_template
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
#!/usr/bin/env python3
# coding: utf-8
#
### py/lint: disable=wrong-import-position
#
'''
A simple python template that ultilize argparse to take CLI arguments
'''
import argparse
#import sys
#sys.path.insert(0, "..")
#from myutil import MyDebug
def main():
''' main '''
msg = 'hello world'
print(f'\{{msg}\}')
parser = argparse.ArgumentParser(description='brief description for this script')
# nargs like regexp, '*' means 0+, '+' means 1+
parser.add_argument("strings", metavar='str', type=str, nargs='*',
help="show these strings")
parser.add_argument('-o', '--output', help='Output file name', default='stdout')
parser.add_argument("-v", "--verbose", action='store_true', default=False,
help='verbose mode')
parser.add_argument("--zoo", dest="zoo", help="no short and assign dest")
# define the required args
requiredNamed = parser.add_argument_group('required named arguments')
requiredNamed.add_argument('-i', '--input', help='Input file name', required=True)
#parser.parse_args(['-i input.txt -o out.txt str1 str2'])
args = parser.parse_args()
print(args.strings)
if args.output:
print('output:', args.output)
if args.input:
print('input:', args.input)
# to show help message directly
#parser.print_help()
if __name__ == '__main__':
main()