June 24, 2021
9:41 a.m.
On Thu, 24 Jun 2021 at 17:37, Martin (gzlist) <gzlist@googlemail.com> wrote:
>>> d = dict(a=1) >>> f'{d["a"]}' '1' >>> str(DelayedFString('{d["a"]}')) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 5, in __str__ KeyError: '"a"'
And the other side of the attribute lookup: >>> d = dict(a=1) >>> str(DelayedFString('{d[a]}')) '1' >>> f'{d[a]}' Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'a' is not defined Yes, having three different ways of doing string interpolation (not counting other things you can import, like string.Template) is a bit confusing. Martin