args是一个除去有用参数外其他的命令行输入 ( 'c', 'd' )
import sysimport getoptdef main(argv): try: opts, args = getopt.getopt(argv, "hs:abc" , ["help", "score=", "format"]) print(opts) print(args) except Exception, err: print(str(err))if __name__ == "__main__": main(sys.argv[1:])测试1:python test_argv.py --help --score=90 --format -a -s -b -c -hh [('--help', ''), ('--score', '90'), ('--format', ''), ('-a', ''), ('-s', '-b'), ('-c', ''), ('-h', ''), ('-h', '')] []
测试2:python test_argv.py --help --score=90 --format -a -s -b -c -kk option -k not recognized
待续一下