我在 Solaris 服务器上安装了 python2.7,并且正在使用 Python 脚本argparse
来检索命令行选项。
在我开始使用子解析器之前,一切都很好。该脚本未能给出此错误:
AttributeError: 'ArgumentParser' object has no attribute 'add_subpasers'
这是脚本的简短副本:
def main():
parser = argparse.ArgumentParser(prog="myProg")
subparsers = parser.add_subpasers (title="actions", description="list of available actions", help="additional help")
parser.add_argument("-v", "--verbose", \
action="store_const", \
dest="VERBOSE", \
default=False, \
const=True, \
help="runs in verbose mode")
parser.add_argument("-V", "--version", \
action="version", \
version="myProg 0.1", \
help="prints the version number")
parser.add_argument("-z", \
type = file, \
required = True, \
dest = "CONF_FILE", \
help = "defines the configuration file")
parser.add_argument("-f", \
type = file, \
required = True, \
dest = "ENV_FILE", \
help = "defines the env definition file")
parser.add_argument("-e", \
dest = "target_env", \
default = None, \
help = "limits actions to a specific service. (Optional)")
parser_launch = subparsers.add_parser ("launch", help = "launches the environment")
parser_create = subparsers.add_parser ("create", help = "creates the environment")
parser_create.add_argument ("-p", type = int, help = "passes the necessary parameters for creation")
pymss_namespace = parser.parse_args()
知道为什么吗?非常感谢。