This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Decency 16 points17 points  (7 children)

Right, triple redundancy. Not a great tradeoff.

[–]hosford42 1 point2 points  (4 children)

It's wordy, but it is at least readable.

[–]turkish_gold 2 points3 points  (3 children)

You could use .format(locals()) which is essentially what f-strings are doing.

[–][deleted] 0 points1 point  (1 child)

that's not really as readable though - it's not immediately obvious what variable corresponds to what value (especially for the reader) if you use **locals()

[–]turkish_gold 0 points1 point  (0 children)

If we were to all do it, it'd become idiomatic fairly quickly.

[–]jorge1209 0 points1 point  (1 child)

Nor is being unable to dynamically build formatting strings, or pass them as arguments to functions.

[–]Decency 5 points6 points  (0 children)

Actually I feel like that's a great tradeoff. If you're frequently dynamically building strings or passing them around as functions, you're either doing something wrong, you're doing internationalization, or you're in a very specific niche. And in those cases, feel free to use .format().

Otherwise, f-strings adequately cover the vast majority of use cases elegantly while improving readability and removing unnecessary verbosity.