我有包含字符串的变量:
a = "y"
b = "="
c = "2"
d = "+"
e = "3"
I want to construct with metaprograming inside function with something like a+b+c+d+e
code that with current content of the variables above should yield y=2+3
and after return with metaprogramming content of a
which is y
in your case.
像这样的伪代码:
a = "y"
b = "="
c = "2"
d = "+"
e = "3"
def fun(a, b, c, d):
execute(a+b+c+d+e)
return a
x = fun(a, b, c, d)
print(x)
Expected output of print(x)
is 5
.
Question: How to archive that with good practices and safe way? I know that exec()
is not considered as a good practice and safe way to do that.