python提供getopt模块解析命令行参数。
官方文档地址:https://docs.python.org/2.7/library/getopt.html
我目前使用的还是python 2.7。其他版本的文档在官网也很容易找到。
官网文档写的十分好,例子也很清晰,不赘述。
有句话需要注意下,没看文档前被这个问题困扰了很久:
Long options on the command line can be recognized so long as they provide a prefix of the option name that matches exactly one of the accepted options. For example, if long_options is ['foo', 'frob'], the option --fo will match as --foo, but --f will not match uniquely, so GetoptError will be raised.