| ▲ | gucci-on-fleek 2 hours ago | |
> What happened to "one-- and preferably only one --obvious way to do it"? There arguably still is—just use f-strings for everything, unless you need to support ancient Python, in which case use %-formatting. t-strings are a special case, but in theory most functions should only accept regular strings or templates, so there should only be one choice there too. > Also, the way string formatting interacts with logging is a total mess [...] it doesn't allow you to use late evaluation based on log level. This all seems to be a side-effect of the fact that string formatting produces static strings, so I don't think that there's much that can be done here (but maybe t-strings can be creatively used here somehow). | ||
| ▲ | vova_hn2 an hour ago | parent | next [-] | |
> maybe t-strings can be creatively used here somehow Maybe they could, but I would be the first to oppose introducing creative ways to do logging or string formatting. Such basic things should be done in the most standard way possible to reduce cognitive effort required to read and understand the code. But the standard way is kinda ugly. Most people would expect f-strings to be used for "normal" string formatting and %-style to be used for logging, because it is the default and most codebases do it this way. Therefore, you basically forced to have (at least) two different formatting syntaxes in your codebase. I say "at least", because if the program serves html pages, you most likely also have some other template engine like jinja... | ||
| ▲ | 2 hours ago | parent | prev [-] | |
| [deleted] | ||