On 2023-04-29 08:31, Matsuoka Takuo wrote:
On Sat, 29 Apr 2023 at 00:52, MRAB <python@mrabarnett.plus.com> wrote:
What happens if you do '{open}...{close}'.partial_format(open='{close}'? You get '{close}...{close}', and you're going to have a problem using that as a format string and replacing only the second '{close}'.
Or how about '{open}...{close}'.partial_format(open='{')? You get '{...{close}'. Try using that as a format string!
That's why I think that the result of a partial format should be an instance of a new class and not a string.
That's a quite subtle point. I think '{open}...{close}'.partial_format(open='{close}') could be the string
'{open}...{close}'.format(open='{{close}}', close='{close}')
and '{open}...{close}'.partial_format(open='{') could be '{open}...{close}'.format(open='{{', close='{close}')
You might not know what the replacements are until runtime, so: '{open}...{close}'.partial_format(open=opening_item)