标签:etop sys --help getopt code pytho span print class
test.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import getopt import sys #-h-f-v为了下面的识别 opts,args = getopt.getopt(sys.argv[1:],‘-h-f-v‘,[‘help‘,‘filename=‘,‘version‘]) #print(opts) for opt_name,opt_value in opts: if opt_name in (‘-h‘,‘--help‘): print("[*] Help info") sys.exit() if opt_name in (‘-v‘,‘--version‘): print("[*] Version is 0.01 ") sys.exit() if opt_name in (‘-f‘,‘--filename‘): fileName = opt_value print("[*] Filename is ",fileName) # do something sys.exit()
运行test.py -v
打印 "[*] Version is 0.01 "
标签:etop sys --help getopt code pytho span print class
原文地址:https://www.cnblogs.com/kevincaptain/p/10193797.html