3 ms·
Logging modules mostly, especially if you have objects that can take a while to serialize to a string, can benefit from the "old" format string approaches. (Per
by noirscape 3y ago
Logging modules mostly, especially if you have objects that can take a while to serialize to a string, can benefit from the "old" format string approaches. (Percent formatting is for some reason favored, although there's no real good reason to not just use the .format() approach outside of the standard logging library being a dinosaur.)
For conditional formatting (where you don't know if the formatting is needed or the contents of what you're formatting into the string but you know what you want to format), f-strings also lose their use pretty much immediately.
They're great for a quick inline format but less useful for things like string templates you want to use over and over.
- pama 3y agoAgreed about conditional formatting in current practice, though I wonder how much of it is historical momentum and how Python could have developed if it started with f-strings only. One could use simple functions for replacing string templates if f-strings were the only option.