python getopt使用_如何使用getopt.getoptpython中的方法?

我想添加警告和严重警告条件if inputfile == "android":通过,然后检查存储在变量e and f中的数字,并检查它是否处于正常、警告或严重级别,不管我们传递的参数是什么。

其次,这个脚本在python3.6中运行时没有输出#!/usr/bin/python

import requests, os, json, sys, getopt

f = 10

e = 20

def main(argv):

inputfile = ''

try:

opts, args = getopt.getopt(argv,"hi:o:w:c:",["ent","lable","help","warning","critical"])

except getopt.GetoptError:

print ("Usage: test.py -i ")

sys.exit(2)

for opt, arg in opts:

if opt == '-h':

print ("test.py -i ")

sys.exit()

# elif opt in ("-i", "--app"):

elif opt == '-i':

inputfile = arg

if inputfile == "android":

'''call a function here (hiding sensitive information) Using e and f variable instead'''

print ("Input is"), inputfile

print("Active:"), f

else:

print("Parameter not found")

sys.exit(2)

# elif opt in ("-o", "--lable"):

elif opt == '-o':

inputfile = arg

print("Active:"), e

if __name__ == "__main__":

main(sys.argv[1:])

现在:

#python script -i android

输出

Active: 10

期望:

#python script -i android -w 5 -c 20

输出

WARNING - Active: 10

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值