4 ms·
I'm sorry, but I think you missed my point here. There's now four different ways to do string interpolation, which means that to understand someone else's code,
by yen223 10y ago
I'm sorry, but I think you missed my point here. There's now four different ways to do string interpolation, which means that to understand someone else's code, I will need to know how `%`, `.format`, `string.template` and `f` works - I won't know which method the library author uses. I will need to know how they break in edge cases (and they will be broken, otherwise we wouldn't have replaced them!)
Worse still, I will also need to know how they interact with each other - you can do
something = "abc"
x = f"{something}".format(something="def")
and I honestly have no idea what x will be.
So yeah, I would love to "use f strings and stop complaining", but the fact that the other string interpolation methods still exist, and are still supported, is still going to be a problem.
- mixmastamyk 10y agoIt will be an error, the {something} will be gone by the time the second .format runs. It might help to realize the f-string is just syntactic sugar for a .format() call.
- hyperbovine 10y agoIt's not obvious which .format() is evaluated first, though. For 'in-line' string interpolation I think the f'' syntax wins. .format() is still nice for template-style interpolation though. For this reason, and to avoid situations like the parent, I think it should be made static, so that you could write: >>> formatted = str.format(template, var1='a', var2=3) Of course, this will never happen due to the need to maintain backward compatibility.
- mixmastamyk 10y agoIn python, function calls start from left and continue to the right. Though f'' doesn't look like a function call, in practice it is.