<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Aug 5, 2015 at 9:34 PM, Yury Selivanov <span dir="ltr"><<a href="mailto:yselivanov.ml@gmail.com" target="_blank">yselivanov.ml@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 2015-08-05 2:56 PM, Eric V. Smith wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In the "Briefer string format" thread, Guido suggested [1] in passing<br>
that it would have been nice if all literal strings had always supported<br>
string interpolation.<br>
<br>
I've come around to this idea as well, and I'm going to propose it for<br>
inclusion in 3.6. Once I'm done with my f-string PEP, I'll consider<br>
either modifying it or creating a new (and very similar) PEP.<br>
<br>
The concept would be that all strings are scanned for \{ and } pairs. If<br>
any are found, then they'd be interpreted in the same was as the other<br>
discussion on "f-strings". That is, the expression between the \{ and }<br>
would be extracted and searched for conversion characters and format<br>
specifiers. The expression would be evaluated, converted if needed, have<br>
its __format__ method called, and the resulting string inserted back in<br>
to the original string.<br>
<br>
Because strings containing \{ are currently valid, we'd have to<br>
introduce this feature with a __future__ import statement. How we<br>
transition to having this be the default interpretation of strings is up<br>
in the air.<br>
</blockquote>
<br></span>
Have you considered using '#{..}' syntax (used by Ruby and<br>
CoffeeScript)?<br></blockquote><div><br></div><div>Well, I feel bound by *some* backward compatibility... Python string literals don't treat anything special except \ followed by certain characters. It feels better to add to the set of "certain characters" (which we've done before) than to add a completely new escape sequence.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
'\{..}' feels unbalanced and weird.<span class="HOEnZb"><font color="#888888"></font></span><br></blockquote></div><br></div><div class="gmail_extra">Not more or less than '#{..}'. I looked through <a href="https://en.wikipedia.org/wiki/String_interpolation">https://en.wikipedia.org/wiki/String_interpolation</a> for what other languages do, and it reminded me that Swift uses '\(..)' -- that would also be a possibility, but '\{..}' feels closer to the existing PEP 3101 '{..}.format(..) syntax.<br><br></div><div class="gmail_extra">And I did indeed mean for r-strings not to be interpolated (since they are exempt from \ interpretation).<br><br></div><div class="gmail_extra">We should look a bit more into how this proposal interacts with regular expressions (where \{ can be used to avoid the special meaning of {..}). I think \(..) would be more cumbersome than \{..}, since () is more common in regular expressions than {}.<br><br></div><div class="gmail_extra">BTW an idea on the transition: with a __future__ import \{..} is enabled in all non-raw strings, without a __future__ import you can still use \{..} inside f-literals. (Because having to add a __future__ import interrupts one's train of thought.)<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>