[Python-ideas] String interpolation for all literal strings

Guido van Rossum guido at python.org
Thu Aug 6 23:00:58 CEST 2015


On Thu, Aug 6, 2015 at 9:02 PM, Wes Turner <wes.turner at gmail.com> wrote:
>
> On Wed, Aug 5, 2015 at 8:58 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>
>> On 8/5/2015 3:34 PM, Yury Selivanov wrote:
>>
>> '\{..}' feels unbalanced and weird.
>>>
>>
>> Escape both.  The closing } is also treated specially, and not inserted
>> into the string.  The compiler scans linearly from left to right, but human
>> eyes are not so constrained.
>>
>> s = "abc\{kjljid some long expression jk78738}def"
>>
>> versus
>>
>> s = "abc\{kjljid some long expression jk78738\}def"
>>
>> and how about
>>
>> s = "abc\{kjljid some {long} expression jk78738\}def"
>
>
> +1: escape \{both\}.
>

That looks worse to me. In my eyes, the construct has two parts: the \ and
the {...}. (Similar to \N{...}, whose parts are \N and {...}.) Most of the
time the expression is short and sweet -- either something like \{width} or
\{obj.width}, or perhaps a simple expression like \{width(obj)}. Adding an
extra \ does nothing to enhance readability.

Giving long or obfuscated expressions that *could* be written using some
proposed feature to argue against it is a long-standing rhetoric strategy,
similar to "strawman".

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150806/13548121/attachment.html>


More information about the Python-ideas mailing list