79286442

Date: 2024-12-17 01:11:30
Score: 0.5
Natty:
Report link

I came upon this question which was similar to something I was trying to do, the only difference is that I needed some of the variables for my f-string evaluated early and then defer other f-string variables to be determined later.

So to borrow from the original example, here's how I pulled it off:

from datetime import date
now = date.today()
names = ["foo", "bar"]

# double bracket allows `name` to be evaluated by the next format() call
template_a = f"The current name is {{name}} and the current date is {now}."

for name in names:
    print (template_a.format(name=name))
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: rsouthwi