Comment

Comment by WhyNotHugo

More flexible f-string parsing sounds like a mistake. The basic use case is fine:

    f"Hello, {name}, how are you?"
But putting entire expressions in there sounds like going too far. So now you can do this:

    f" something { my_dict["key"] } something else "
But why not the simpler approach (this is simper to read for both humans and machines):

    value = my_dict["key"]
    f" something {value} something else "
Heck, even this monstrosity is allowed:

    f"{f"{f"{f"{f"{f"{1+1}"}"}"}"}"}"
From TFA (emphasis mine):

> Expression components inside f-strings can now be any valid Python expression including backslashes, unicode escaped sequences, *multi-line expressions*, comments and strings reusing the same quote as the containing f-string.

Edit: I do appreciate that at least the parser will give out detailed error messages when something is wrong in a f-string.

parent WhyNotHugo 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton