I've read How do I convert a string into an f-string? and How to postpone/defer the evaluation of f-strings? and have seen many (working) solutions with exec
to postpone the execution of an f-string, like:
template = "My name is {name} and I am {age} years old"
name = 'Abcde'
age = 123
s = eval('f"""' + template + '"""') # My name is Abcde and I am 123 years old
Is there an internal Python function (among the many double underscore __something__
functions), that defines how the interepreter "runs" / "interpolates" an f-string?
Is there something like __runfstring__
in the Python source code, which is responsible for execution of code? If so, could we call this function ourselves with something like:
s = __runfstring__(template)
in the latest Python versions? (3.7 or 3.8+)