I'd like to defer the rendering of one so that I could do something like this:
TEMPLATE = '{variable}'
variable = 2
print(f(TEMPLATE)) # 2
variable = 4
print(f(TEMPLATE)) # 4
My use-case is actually somewhat more complex than this, but being able to template out my strings at a high-level and then format them later is useful I know I can TEMPLATE.format({'variable': 2})
but I'm after something a bit more... magic.
How do f-strings actually work? How do they pass the local scope into format()
?