[Python-Dev] Subtle difference between f-strings and str.format()
Nick Coghlan
ncoghlan at gmail.com
Fri Mar 30 06:25:01 EDT 2018
On 30 March 2018 at 20:05, Serhiy Storchaka <storchaka at gmail.com> wrote:
> 30.03.18 02:16, Steven D'Aprano пише:
>>
>> Is there a down-side to 2b? It sounds like something you might end up
>> doing at a later date regardless of what you do now.
>
>
> This complicate the compiler and the eval loop, especially in the case of
> nested substitutions in formats, like
>
> f'{value:+{width:d}.{prec:d}f}'
This point reminded me that there's still
https://www.python.org/dev/peps/pep-0536/ to consider as well (that's
the PEP about migrating f-strings to a fully nested expression grammar
rather than hijacking the existing string tokenisation code).
I *think* that's an orthogonal concern (since it relates to the
initial parsing and AST compilation phase, rather then the code
generation and execution phase), but it's worth keeping in mind.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list