[Python-ideas] String interpolation for all literal strings

Yury Selivanov yselivanov.ml at gmail.com
Wed Aug 5 21:34:54 CEST 2015


On 2015-08-05 2:56 PM, Eric V. Smith wrote:
> In the "Briefer string format" thread, Guido suggested [1] in passing
> that it would have been nice if all literal strings had always supported
> string interpolation.
>
> I've come around to this idea as well, and I'm going to propose it for
> inclusion in 3.6. Once I'm done with my f-string PEP, I'll consider
> either modifying it or creating a new (and very similar) PEP.
>
> The concept would be that all strings are scanned for \{ and } pairs. If
> any are found, then they'd be interpreted in the same was as the other
> discussion on "f-strings". That is, the expression between the \{ and }
> would be extracted and searched for conversion characters and format
> specifiers. The expression would be evaluated, converted if needed, have
> its __format__ method called, and the resulting string inserted back in
> to the original string.
>
> Because strings containing \{ are currently valid, we'd have to
> introduce this feature with a __future__ import statement. How we
> transition to having this be the default interpretation of strings is up
> in the air.

Have you considered using '#{..}' syntax (used by Ruby and
CoffeeScript)?

'\{..}' feels unbalanced and weird.

Yury


More information about the Python-ideas mailing list