>>> mycode = "a = int(raw_input()); print a * 2; return a" >>> myfunc = FunctionType(compile(mycode, "<string>", "exec"), globals()) >>> myfunc() 4 8 4
>>> from types import * >>> mycode = "a = int(raw_input()); print a * 2; return a" >>> myfunc = FunctionType(compile(mycode,"<string>","exec"), globals()) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1 SyntaxError: 'return' outside function Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1 SyntaxError: 'return' outside function