有没有办法用字符串替换Python代码?

时间:2019-05-11 23:02:13

标签: python string

我在Python中有一个返回函数结果的代码,并且我正在使用带有flask的应用程序。目的是让用户像在Python中那样输入函数,然后由应用程序为他们解决,有没有办法将字符串转换为代码?

-- Input from website --
"math.log((math.sin(x)**2) + 1) - (1 / 2)"

def f(x):
    return math.log((math.sin(x)**2) + 1) - (1 / 2)

0 个答案:

没有答案
相关问题