I was playing around with argparse in python. I had something like below:
group_gen.add_argument('--switch', nargs=2, metavar=('PARAM1', 'PARAM2'))
I then removed PARAM2 so I had:
group_gen.add_argument('--switch', nargs=2, metavar=('PARAM1', 'PARAM2'))
Then whenever argparse had to print help, I would get the following exception with stack trace
Traceback (most recent call last):
File "./script.py", line 20, in <module>
args = parser.parse_args()
File "/usr/lib/python2.7/argparse.py", line 1688, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/lib/python2.7/argparse.py", line 1727, in parse_known_args
self.error(str(err))
File "/usr/lib/python2.7/argparse.py", line 2346, in error
self.print_usage(_sys.stderr)
File "/usr/lib/python2.7/argparse.py", line 2308, in print_usage
self._print_message(self.format_usage(), file)
File "/usr/lib/python2.7/argparse.py", line 2264, in format_usage
return formatter.format_help()
File "/usr/lib/python2.7/argparse.py", line 279, in format_help
help = self._root_section.format_help()
File "/usr/lib/python2.7/argparse.py", line 209, in format_help
func(*args)
File "/usr/lib/python2.7/argparse.py", line 317, in _format_usage
action_usage = format(optionals + positionals, groups)
File "/usr/lib/python2.7/argparse.py", line 449, in _format_actions_usage
args_string = self._format_args(action, default)
File "/usr/lib/python2.7/argparse.py", line 587, in _format_args
result = ' '.join(formats) % get_metavar(action.nargs)
TypeError: not enough arguments for format string
Why am I getting this error?
I was having trouble figuring out what was going on, then it dawned on me, with the command format string
I think your question is typo’d badly, but try this:
Is that what you’re trying to do?