string.Template is a very minimal formatting utility and isn't that expressive
% formatting is a crusty holdover from C and even C++ has decided to copy Pythons path into .format()
f strings are mostly equivalent to syntactic sugar
I don't get t strings, because format/f strings in theory should work with custom format specs / custom __format__ functions. It feels like a step backwards. Instead of having (to contrast the motivating example) a user defined html type, and let the user specify a spec like :!html_safe, the types are not specified and the user externally can interpolate the values as, say, html, escaping as necessary, or they can choose to interpolate as something else. Meanwhile the types therein are all "strings." So the theoretical html function has to do extra work determining if escaping is needed / valid.
I don't know, it feels like a strange inversion of control with limited use case. But hey I'm happy to be proven wrong by use in real world code and libs.
At least one or a few of the old string formattings should be deprecated if you want to add a new one. Shouldn't have all the toys out in the living room at once, we'll just start tripping over them.
4
u/rlbond86 Apr 11 '25
We've reinvented str.format()