#!-*-coding:utf8 -*-
#要在首行才可以在后面用中文注释
import getopt
import sys
import os
if __name__ == '__main__':
# ...
helpdoc = '''
Description
...
Usage
python pyscript.py -i/--ifile <input file> -o/--ofile <output file> -t/--time <int> ...
Parameters
-h/--help
Print helpdoc
-i/--ifile
Input file,including only one column with sampleId
-o/--ofile
Output file, including two columns, the 1st column is sampleId, the 2nd column is attribute information
-t/--time
Time for interval (seconds, default 5s)
...
'''
try:
opts,args = getopt.getopt(sys.argv[1:], "hi:o:t:n:", ["help","ifile=", "ofile=", "time="])
if len(opts) == 0:
print("Options Error!\n\n"+helpdoc)
sys.exit(2)
except getopt.GetoptError:
print("Options two Error!\n\n"+helpdoc)
sys.exit(2)
for opt,arg in opts:
if opt in ("-h","--help"):
print(helpdoc)
sys.exit()
elif opt in ("-i","--ifile"):
infile = arg
elif opt in ("-o","--ofile"):
outfile = arg
elif opt in ("-t","--time"):
sleep_time = int(float(arg))
elif opt in ("-n","--requests-number"):
requestNum = int(float(arg))
print (infile)
print (outfile)
print (sleep_time)
print (requestNum)
参考 1、python参数输入 2、cmdbtools