You can try using the eval() function, it evaluates a string, and executes it as python code if it is valid as python code.