-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.py
64 lines (53 loc) · 1.49 KB
/
sample.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
58
59
60
61
62
63
64
#! /usr/bin/env python
#
# python script template file
#
# @date: 2013-2-2
# @author: yeyanbo
##import other module
import getopt
import sys
def usage():
""" modify this for usage information"""
usage = """Usage: python script.py -i [input file] -o [output file]
Option:
-h,--help Print this usage
-i,--input input file
-o,--output output file
"""
print usage
def main():
""" main work flow should be in the main function"""
#get options and arguments
#modify options to your version as described in the usage() function
try:
opts, args = getopt.getopt(sys.argv[1:], "i:o:h", ["input=", "output=", "help"])
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(2)
#default value of options and arguments
#modify default value to your version
infile = None
outfile = None
#parse options
#modify this accordingly
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-i", "--input"):
infile = a
elif o in ("-o", "--output"):
outfile = a
else:
assert False, "unhandled option"
#check options and print usage if unexpected
#modify this accordingly
if infile == None or outfile == None:
usage()
sys.exit(2)
#real work flow goes here
print "input file is '%s' and output file is '%s'" % (infile, outfile)
if __name__ == "__main__":
main()