【发布时间】:2020-06-19 06:55:33
【问题描述】:
这是我的简单 test.py 脚本:
import argparse
parser = argparse.ArgumentParser('A long string that goes on and on and on'
'and on and on and on and on and on and on '
'and on and on and on and on and on and on '
'and on and on and on and on and on and on ')
me_group = parser.add_mutually_exclusive_group()
me_group.add_argument('-f', help=argparse.SUPPRESS)
me_group.add_argument('-o', help=argparse.SUPPRESS)
parser.add_argument('-t', help='c')
parser.parse_args()
当我运行以下命令时:
python test.py --help
我得到了这个 AssertionError:
...
File "/usr/lib/python2.7/argparse.py", line 332, in _format_usage
assert ' '.join(opt_parts) == opt_usage
AssertionError
这似乎只发生在我压制一个互斥组中的所有论点时。如果一个或多个没有被抑制,那么一切正常。如果我打印出比较的两侧:
print ' '.join(opt_parts)
print opt_usage
我得到以下信息:
[-h] [-t T]
[-h] [-t T]
看起来那里有一个额外的空间。知道为什么会这样吗?是不是我做错了什么?
【问题讨论】:
标签: python python-2.7 argparse