try:
opts,args=getopt.getopt(sys.argv[1:],"hi:l:",["help", "interval=","list="])
except getopt.GetoptError:
print "Error "#info as you want to give out
sys.exit()
[...]# 对附加参数的进一步分析处理.即输入参数在语法意义上合法,但不一定在语义意义上合法.例如
for opt,value in opts:
if opt == "-i":
if not(value.isdigit()):#-i后面的附加参数应该是数字
print "after -i, should be integer "
sys.exit()
else:
interval=int(value)
[...]