Q:

Python (SymPy, SciPy), create symbol lambda from string

I've struggling to take text inputs of an equation and evaluate it as a definite integral. I need a callable function to pass to scipy.integrate. 
eq = "x**2"
func = lambda x: eq
func(2)

# outputs:
# x**2

# but if I:

func = lambda x: x**2
func(2)

# outputs:
# 4

A:

Not sure, but maybe you are looking for
eq = "x**2"
func = eval("lambda x: " + eq)

Note that using eval() is dangerous if eq is from an untrusted source (e.g. user input).

