This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: argparse produces error when multiply help lines
Type: Stage: resolved
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Nikolay.Golub, r.david.murray
Priority: normal Keywords:

Created on 2012-08-30 14:14 by Nikolay.Golub, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg169456 - (view) Author: Nikolay Golub (Nikolay.Golub) Date: 2012-08-30 14:14
When i use this code:
  parser.add_argument('-r', '--range',
                        action = 'store',
                        dest = 'ranges',
                        nargs = 2,
                        metavar = 'RANGE',
                        required = False,
                        help = 'Start and end range date and time for report data.'\
                                'Timeformat is %y-%m-%d %H:%M:%S'\
                                'for example -r "2012-08-20 14:48:39 "2012-08-25 15:35:00"'

I get this error:

Traceback (most recent call last):
  File "./", line 166, in <module>
  File "./", line 123, in main
    args = parser.parse_args()
  File "/usr/lib/python2.7/", line 1688, in parse_args
    args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python2.7/", line 1720, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python2.7/", line 1926, in _parse_known_args
    start_index = consume_optional(start_index)
  File "/usr/lib/python2.7/", line 1866, in consume_optional
    take_action(action, args, option_string)
  File "/usr/lib/python2.7/", line 1794, in take_action
    action(self, namespace, argument_values, option_string)
  File "/usr/lib/python2.7/", line 994, in __call__
  File "/usr/lib/python2.7/", line 2313, in print_help
    self._print_message(self.format_help(), file)
  File "/usr/lib/python2.7/", line 2287, in format_help
    return formatter.format_help()
  File "/usr/lib/python2.7/", line 279, in format_help
    help = self._root_section.format_help()
  File "/usr/lib/python2.7/", line 209, in format_help
  File "/usr/lib/python2.7/", line 209, in format_help
  File "/usr/lib/python2.7/", line 515, in _format_action
    help_text = self._expand_help(action)
  File "/usr/lib/python2.7/", line 601, in _expand_help
    return self._get_help_string(action) % params
ValueError: unsupported format character 'y' (0x79) at index 65

i think that it sin't normal. i always cut strings like these, according to pep8
msg169457 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-08-30 14:23
The problem is the timeformat.  % codes are used to include data into the strings, so if you want a literal % in the help string, you need to double it.
msg169459 - (view) Author: Nikolay Golub (Nikolay.Golub) Date: 2012-08-30 14:35
Date User Action Args
2022-04-11 14:57:35adminsetgithub: 60027
2012-08-30 14:35:20Nikolay.Golubsetmessages: + msg169459
2012-08-30 14:24:16r.david.murraysetstatus: open -> closed
resolution: not a bug
stage: resolved
2012-08-30 14:23:52r.david.murraysetnosy: + r.david.murray
messages: + msg169457
2012-08-30 14:14:21Nikolay.Golubcreate