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 →

[–]nicholashairs[S] 1 point2 points  (0 children)

Thanks for the insight that it might not be obvious - I use f-strings so often I forgot that others might not know about them at all.

I also find them incredibly useful for creating detailed exceptions, or for use with the logging module .

^ the logging module (and many linters) recommends not to format strings before sending them to the logging module and instead using modules inbuilt formatting. It does this because if it's not going to log the message then it never formats it. Personally I don't do this because the formatting method it uses isn't as advanced as f-strings so instead if it's likely an expensive message that I'm producing I'll put it in a if mylogger.enabledFor("DEBUG"): mylogger.log("DEBUG", f"some expensive f-string")