如何在argparse python中实现* args和** kwargs

时间:2017-09-08 00:02:53

标签: python python-2.7

这是我的代码

import argparse

parser = argparse.ArgumentParser()

parser.add_argument("required_arg", metavar="username:pass@hostname")
parser.add_argument("--optional_arg", 
                    help="This optional argument should have args and 
                          kwargs implemented in it as I want to make 
                          it flexible eg.
                          it may have optional_arg1, 
                          optional_arg2, key1=value1, key2=value2 or 
                          it may have optional_arg1, key1=value1, 
                          key2=value2, key3=value3")

有人能告诉我在这个add_argument()部分实现* args和** kwargs的方法吗?

1 个答案:

答案 0 :(得分:0)

我想你可能想看看这样的事情:

parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='subparser')