如何解决parser.add_argument的问题

时间:2019-04-17 03:06:14

标签: python-3.x argparse

我正在尝试将metavar信息添加到特定的命令行参数,并且当我在方括号中添加信息时,Python会引发错误。

如果括号中有“ Bq”,则会出现错误。如果我没有括号(或括号之间没有),则不会出错。

parser.add_argument("--dispensed_activity", dest="aDActivity", type=int,  action="store", required=True, metavar="<amount dispensed (Bq)>", help="Activity dispensed (Bq)")

错误堆栈为:

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 1730, in parse_args
args, argv = self.parse_known_args(args, namespace)

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 1762, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 1997, in _parse_known_args
', '.join(required_actions))

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 2387, in error
self.print_usage(_sys.stderr)

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 2357, in print_usage
self._print_message(self.format_usage(), file)

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 2323, in format_usage
return formatter.format_help()

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 282, in format_help
help = self._root_section.format_help()

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 213, in format_help
item_help = join([func(*args) for func, args in self.items])

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 213, in 
item_help = join([func(*args) for func, args in self.items])

File "C:\python\python-3.6.1.amd64\lib\argparse.py", line 333, in _format_usage
assert ' '.join(opt_parts) == opt_usage

AssertionError

0 个答案:

没有答案