标签:通过 实现 cas 命令行 参数 并且 png 元组 /usr
import getopt import sys arg = getopt.getopt(sys.argv[1:],‘-h‘,[‘help‘]) print(arg)
root@Kali:~/python# python3.5 test.py -h ([(‘-h‘, ‘‘)], []) root@Kali:~/python# python3.5 test.py --help ([(‘--help‘, ‘‘)], [])
1 #!/usr/bin/env python3.5 2 import urllib.request 3 import getopt 4 import sys 5 6 opts,args = getopt.getopt(sys.argv[1:],‘-h-f:-v‘,[‘help‘,‘filename=‘,‘version‘]) 7 for opt_name,opt_value in opts: 8 if opt_name in (‘-h‘,‘--help‘): 9 print("[*] Help info") 10 exit() 11 if opt_name in (‘-v‘,‘--version‘): 12 print("[*] Version is 0.01 ") 13 exit() 14 if opt_name in (‘-f‘,‘--filename‘): 15 fileName = opt_value 16 print("[*] Filename is ",fileName) 17 # do something 18 exit()
root@Kali:~/python# python3.5 test.py --filename=test [*] Filename is test root@Kali:~/python# python3.5 test.py --filename= [*] Filename is root@Kali:~/python# python3.5 test.py --help [*] Help info root@Kali:~/python# python3.5 test.py --version [*] Version is 0.01 root@Kali:~/python# python3.5 test.py -v [*] Version is 0.01 root@Kali:~/python# python3.5 test.py -f test [*] Filename is test root@Kali:~/python#
标签:通过 实现 cas 命令行 参数 并且 png 元组 /usr
原文地址:http://www.cnblogs.com/gentlemanhai/p/7771709.html