Re:Python 3's F-Strings: An Improved String Formatting Syntax
by ploxiln on Wednesday January 20, 2021 @10:45PM
(#25855139)
> In Python 3.2, the Formatter gained a style keyword parameter which, while defaulting to % for backward compatibility, allowed the specification of { or $ to support the formatting approaches supported by str.format() and string.Template. Note that this governs the formatting of logging messages for final output to logs, and is completely orthogonal to how an individual logging message is constructed.
The style option only applies to the outer format applied by the formatter (timestamp, level, file, line, etc), it does not apply to the logging calls.
You still miss out on the scoping of f-strings, and embedding function calls. But passing around what amounts to an "eval" expression is a footgun that should obviously be frowned upon.
There's also an option for $-style Template strings. But I can't recall when I've ever seen someone use that.