[Python-ideas] String interpolation for all literal strings

Joseph Jevnik joejev at gmail.com
Wed Aug 5 21:18:06 CEST 2015


raw-strings will not be scanned, correct?

On Wed, Aug 5, 2015 at 2:56 PM, Eric V. Smith <eric at trueblade.com> 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.
>
> Guido privately suggested that it might be nice to also support the 'f'
> modifier on strings, to give the identical behavior. This way, you could
> start using the feature without requiring the __future__ import. While
> I'm not crazy about having two ways to achieve the same thing, I do
> think it might be nice to support interpolated strings without requiring
> the __future__ import.
>
> Eric.
>
>
> [1] https://mail.python.org/pipermail/python-ideas/2015-August/034928.html
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150805/b3f1a1c3/attachment-0001.html>


More information about the Python-ideas mailing list