0

Recently I wrote a command-line parsing script using argparse in Python:

# tmp.py
import argparse

args = argparse.ArgumentParser()
args.add_argument('-warmup_proportion', type=float, default=0.1,
                  help="Proportion of training to perform linear learning rate warmup for E.g., 0.1 = 10% of training.")
args.parse_args()

When I run above code:

$python tmp.py -h

It raised a TypeError(only the last few rows for short):

  File "/Users/sunjiawei/opt/anaconda3/envs/py-37-ner/lib/python3.7/argparse.py", line 284, in format_help
    help = self._root_section.format_help()
  File "/Users/sunjiawei/opt/anaconda3/envs/py-37-ner/lib/python3.7/argparse.py", line 215, in format_help
    item_help = join([func(*args) for func, args in self.items])
  File "/Users/sunjiawei/opt/anaconda3/envs/py-37-ner/lib/python3.7/argparse.py", line 215, in <listcomp>
    item_help = join([func(*args) for func, args in self.items])
  File "/Users/sunjiawei/opt/anaconda3/envs/py-37-ner/lib/python3.7/argparse.py", line 215, in format_help
    item_help = join([func(*args) for func, args in self.items])
  File "/Users/sunjiawei/opt/anaconda3/envs/py-37-ner/lib/python3.7/argparse.py", line 215, in <listcomp>
    item_help = join([func(*args) for func, args in self.items])
  File "/Users/sunjiawei/opt/anaconda3/envs/py-37-ner/lib/python3.7/argparse.py", line 531, in _format_action
    help_text = self._expand_help(action)
  File "/Users/sunjiawei/opt/anaconda3/envs/py-37-ner/lib/python3.7/argparse.py", line 620, in _expand_help
    return self._get_help_string(action) % params
TypeError: %o format: an integer is required, not dict

If I delete 0.1 = 10% in help strings, it just worked OK. Is it a bug or something?

My Python is 3.7.9 for MacOS.

S.Carven
  • 21
  • 6
  • 1
    Try `'10%%'`. The help string is used for `%`formatting. https://docs.python.org/3/library/argparse.html#help. For example `help='the bar to %(prog)s (default: %(default)s)'` – hpaulj Jan 04 '21 at 06:00

0 Answers0