def make_func(expr):
    funcstr = """def f(x,p):
    return {e}
    """.format(e=expr)
exec(funcstr)
return f
f = make_func(expr)
print(f(1, [2, 3]))
Python/Numpy/Scipy - Converting string to mathematical function