If you want to do it safely, you may want to use http://docs.python.org/library/ast.html#ast.literal_eval
from this answer:
Python "safe" eval (string to bool/int/float/None/string)
It might not do math, but you could parse the math operators and then operate on safely evaluated terms.