是否可以定义一个函数来表现如下?
text = "def x(a):\treturn a+1"
f = ??(text)
f(1)
>> 2
最佳答案
你可以使用exec()
text = "def x(a):\treturn a+1"
exec(text)
print x(5) # gives 6
关于python - python从字符串中获取函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28720236/