[Python-Dev] PEP 498 f-string: is it a preprocessor?

Victor Stinner victor.stinner at gmail.com
Tue Aug 11 00:22:35 CEST 2015


Le lundi 10 août 2015, Eric V. Smith <eric at trueblade.com> a écrit :

> On 08/10/2015 10:18 AM, Victor Stinner wrote:
> > Hi,
> >
> > I read the PEP but I don't understand how it is implemented. For me, it
> > should be a simple preprocessor:
> >
> > - f'x={x}' is replaced with 'x={0}'.format(x) by the compiler
> > - f'x={1+1}' is replaced with 'x={0}'.format(1+1)
> > - f'x={foo()!r}' is replaced with 'x={0!r}'.format(foo())
> > - ...
> >
> > That's all. No new language, no new function or method.
>
> There is no new function or method being proposed. The "pre-processor"
> is being implemented as the ast is being built. As the PEP says, though,
> the expressions supported aren't exactly the same, so a simple
> conversion to str.format syntax isn't possible.
>

Can you please provide example(s) of f-string(s) which cannot be replaced
by a call to .format() like I did?

Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150811/a5265fe6/attachment.html>


More information about the Python-Dev mailing list