How to evaluate a variable as a Python f-string
问题 I would like to have a mechanism which evaluates an f-string where the contents to be evaluated are provided inside a variable. For example, x=7 s='{x+x}' fstr_eval(s) For the usage case I have in mind, the string s may arise from user input (where the user is trusted with eval ). While using eval in production is generally very bad practice, there are notable exceptions. For instance, the user may be a Python developer, working on a local machine, who would like to use full Python syntax to