【发布时间】:2020-01-23 04:01:39
【问题描述】:
我的代码如下所示:
list_of_choices = ["foo", "bar", "baz"]
parser = argparse.ArgumentParser(description='some description')
parser.add_argument("-n","--name","-o","--othername",dest=name,
choices=list_of_choices
我得到的输出如下:
-n {foo,bar,baz}, --name {foo,bar,baz}, -o {foo,bar,baz},
--othername {foo,bar,baz}
我想要的是:
-n, --name, -o, --othername {foo,bar,baz}
就上下文而言,我们需要为同一个选项提供两个名称是有历史原因的,而实际的选项列表有 22 个元素长,所以看起来比上面的要糟糕得多。
这个问题与Python argparse: Lots of choices results in ugly help output 有细微的不同,因为我没有使用两个单独的选项,并且可以像上面那样将它们全部放在一起。
【问题讨论】: