classification
Title: '%' character in help= for argparse causes ValueError: incomplete format
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Neil Godber, eric.smith, paul.j3, rhettinger
Priority: normal Keywords:

Created on 2020-07-12 23:56 by Neil Godber, last changed 2020-07-13 09:07 by eric.smith. This issue is now closed.

Messages (4)
msg373578 - (view) Author: Neil Godber (Neil Godber) Date: 2020-07-12 23:56
'%' character in help= for argparse causes ValueError: incomplete format. I am attempting to use the percentage character in my help string but get the above error. Presumably argparse assumes % denotes formatting when this is not the case. I have tried f-strings, escape and raw strings, none of which rectify the issue. The only solution is that dev's cannot use % character in argpase help strings which is something of an oddity.
msg373579 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-07-13 00:17
Did you try doubling the % char?


help='%%-age of the value'
msg373584 - (view) Author: Neil Godber (Neil Godber) Date: 2020-07-13 04:24
Hi, yes I did just then and indeed this worked. Wasn't aware of this. Further, curiously I am no longer able recreate this issue so I will close this for now. Sorry for the bother.
msg373588 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-07-13 09:07
It's using normal %-formatting, so the rules applied are in https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting

The last line of the last table in that section mentions literal % characters. I realize it's sort of hard to dig this up if you're just interested in argparse.
History
Date User Action Args
2020-07-13 09:07:40eric.smithsetresolution: not a bug
messages: + msg373588
2020-07-13 04:24:57Neil Godbersetstatus: open -> closed

messages: + msg373584
stage: resolved
2020-07-13 02:26:37xtreaksetnosy: + rhettinger, paul.j3
2020-07-13 00:17:43eric.smithsetnosy: + eric.smith
messages: + msg373579
2020-07-12 23:56:17Neil Godbercreate