There is function in python called eval that takes string input and evaluates it.
eval
>>> x = 1 >>> print eval(\'x+1\') 2 >>>
It doesn't have an inbuilt eval function. However are some packages on hackage that can do the same sort of thing. (docs). Thanks to @luqui there is also hint.