[Python-ideas] Let’s make escaping in f-literals impossible

Brendan Barnwell brenbarn at brenbarn.net
Sat Aug 20 02:32:03 EDT 2016


On 2016-08-19 20:57, C Anthony Risinger wrote:
> In a quality editor, everything about the {...} will tell me I'm writing a
> Python expression. It'll be colored like an expression. It'll do fancy
> completion like an expression. Aw shucks, it*IS*  a Python expression!
> Except for one tiny detail: I'm not allowed to use the quote I use in 95%
> of all my Python code--without thinking--because I already used it at the
> string start :-( It's like this weird invisible ruh-roh-still-in-a-string
> state hangs over you despite everything else suggesting otherwise

	But it IS inside a string.  That's why it's an f-string.  The essence 
of your argument seems to be that you want expressions inside f-strings 
to act just like expressions outside of f-strings.  But there's already 
a way to do that: just write the expression outside of the f-string. 
Then you can assign it to a variable, and refer to the variable in the 
f-string.  The whole point of f-strings is that they allow expressions 
*inside strings*.  It doesn't make sense to pretend those expressions 
are not inside strings.  It's true that the string itself "isn't really 
a string" in the sense that it's put together at runtime rather than 
being a constant, but again, the point of f-strings is to make things 
like that writable as strings in source code.  If you don't want to 
write them as strings, you can still concatenate separate string values 
or use various other solutions.

-- 
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is no 
path, and leave a trail."
    --author unknown


More information about the Python-ideas mailing list