Here is how to execute code in a string, similar to what was shown in your example: >>> s = 'print "hello"' >>> exec s hello Hope this helps.