I'm not a fan of f-strings.
I feel like 90% of new Python features in the last 10 years just increased language complexity without any benefit.
Goofy edge cases aside, I think f-strings are great.
I think this is pretty intuitive (I was able to answer the question correctly before opening the spoiler), but I really like raw string designs in Rust and C++11 that allow you to stop worrying about escaping completely.
Not really about the content of the blog post but am I the only one bothered by the complete lack of capitalization? Granted it may be because of my screen reader but my TTS engine of choice doesn't pause on un-capitalized words/sentences/phrases/etc. which follow a full stop, so this post unless I read it line by line (minus the code) just blends into complete noise.
do not get the funny part of the pythons string.
here's a valid f-string:
>>> f'{'}'}' '}'
Huh? I remember learning the rule that you can't nest quotes inside fstrings if they are the same kind (unlike in bash) - e.g
f"{mydict["foo"]}"
would be a syntax error, but f"{mydict['foo']}"
or f'{mydict["foo"]}'
would be valid.The reason being the same like for the rstring weirdness: The lexer comes first and identifies the string literal, then for fstrings, the python parser is invoked again for each {...} expression to parse it.
This is unlike other nested expressions, which are already split up by the lexer and then parsed in one go.
Did that change at some point?
Great new way to write blog posts!
Whenever I'm building a JSON document, I revert to the old %s syntax just because it's more tidy than an f-string.
Been using python for almost 10 years. I never use any of the funky strings.
Instead of reading like 10 PEPs for f strings, I just use the + operator on strings and backslash escaping, big whoop.
Whenever I read people's takes about Python on HN, I always feel like I'm using an entirely different language.