"{} of very long text here...".format(value)
f"{value} of very long text here..."
"{} of very long text here...".format(value)
f"{value} of very long text here..."
If you don't like using the empty {} (which seems fair enough), you can already use a couple of slightly more verbose but more explicit options:
"{value} of very long text here...".format(**locals)
or (more verbose with many keys) "{value} of very long text here...".format(value=value)
I tend to prefer the latter even with multiple keys, but also think the former is better as it makes it explicit that the string is populated with the locals rather than implicitly doing it to all strings.When we are reading code, we are not usually reading the strings contained within.
We are reading variables names, we are looking at where they are used, where they are assigned, stuff like that.
I very rarely look inside the strings when we are actually reading code. When reading code, strings are just black boxes where nothing can happen. So we can completely ignore them.
With this pep, that will change. And readability takes a big hit. Strings are no longer black boxes.
And actually you can get the " {value} if very long text" format right now using the format function, but it right now requires an explicit list/dictionary of variables.
This explicit list of variables really helps in the context of reading code. And forcing users to write down that explicit list of variables to use, is good.
I usually just go to the end of the line. or if that is not possible, I think I usually look at the next closest thing that obviously is not a string and scan backwards.
I mean, usually I didn't have to do anything consciously (or do a scan) to spot the end of a string.
def f(s):
import sys
return s.format(**sys._getframe(1).f_locals)
Used as a = 1
b = 2
f("{a} + {b}")Also compare the readability of this:
"very long text {value} another long text".\ format(value=value)
vs.
f"very long text {value} another long text"
^ now you have to go and visually search through the whole string to see what is being used in there