[Python-ideas] Escaped braces in format specifiers

Nick Coghlan ncoghlan at gmail.com
Thu May 17 09:56:47 EDT 2018


On 15 May 2018 at 16:23, Eric V. Smith <eric at trueblade.com> wrote:

> I'm busy at the sprints, so I don't have a lot of time to think about this.
>
> However, let me just say that recursive format specs are supported, to a
> depth of 1.
>
> >>> width=10
> >>> f'{"test":{width}}'
> 'test      '
>
> So first the string is basically expanded to:
> f'{"test":10}'
> Then the string is formatted again to produce the final result.
>
> That is why the braces must match: they're being used for recursive format
> specs. There's no mechanism for having braces that aren't inspected by the
> f-string machinery.


https://www.python.org/dev/peps/pep-0536/ also seems worth noting (I don't
actually understand the specifics of that PEP myself,  just making sure
that Ken's aware of its existence if this is an area of interest)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180517/d5af4d38/attachment.html>


More information about the Python-ideas mailing list