Earlier quoted context omitted.
Yup, especially as you often need to access dict's with foo["field"] and you get a syntax error if the f-strings is also f"". JavaScript backtick syntax doesn't lead to this extra syntactic friction.
This is easily avoidable in python by using single quotes for the outer string and double quotes for the inner string, or vice versa. Or, use triple quotes for the outer string.
Python 3's F-Strings: An Improved String Formatting Syntax
21–30 of 147 posts
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#22I wrote a simple Awk script to convert Python with f-string syntax to syntax without it.
(The program had a function to do a more or less proper lexical analysis job; not some flimsy regex substitution hack.)
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#23F-strings have been around for years and this article is at least a few years old. I'm curious why this is coming up now.
I wonder if the submitter was inspired by this tweet that went viral (by python standards) yesterday: https://twitter.com/mariatta/status/1351359518316216321
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#24> However, once you start using several parameters and longer strings, your code will quickly become much less easily readable [...] `"Hello, %s %s. You are %s. You are a %s ...` Minor correction: % formatting allows specifying names for dictionary keys too: In [1]: "%(a)s and %(b)s" % {"a":"A", "b":"B"} Out[1]: 'A and B' In fact I had never switched to using str.format as it just never added enough benefit for me ov…
f"{name.lower()} is funny."
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#25While I know why building f strings is forbidden (they can run arbitrary code), I'm happy to take the risk.
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#26Re: Python 3's F-Strings: An Improved String Formatting Syntax
#27The thing which annoys me most about f strings is I can't build them at runtime, which means I can't just learn/teach f strings. While I know why building f strings is forbidden (they can run arbitrary code), I'm happy to take the risk.
Re: Python 3's F-Strings: An Improved String Formatting Syntax
#28The thing which annoys me most about f strings is I can't build them at runtime, which means I can't just learn/teach f strings. While I know why building f strings is forbidden (they can run arbitrary code), I'm happy to take the risk.
>>> fstring="Hello, {\"world\"}"
>>> eval(f"print(f'{fstring}')")
Hello, worldRe: Python 3's F-Strings: An Improved String Formatting Syntax
#29Re: Python 3's F-Strings: An Improved String Formatting Syntax
#30A couple of years ago I wrote some Python code which took advantage of this syntax. Then it turned it had to run in an environment without it. I wrote a simple Awk script to convert Python with f-string syntax to syntax without it. (The program had a function to do a more or less proper lexical analysis job; not some flimsy regex substitution hack.)