How do I execute a string containing Python code in Python?
You accomplish executing code using exec, as with the following IDLE session:
>>> kw = {} >>> exec( "ret = 4" ) in kw >>> kw['ret'] 4