3 ms·
In a way, there is: >>> mycode = "a = int(raw_input()); print a * 2; return a" >>> myfunc = FunctionType(compile(mycode, "<string>", "exec"), globals())
by icebraining 13y ago
In a way, there is:
>>> mycode = "a = int(raw_input()); print a * 2; return a"
>>> myfunc = FunctionType(compile(mycode, "<string>", "exec"), globals())
>>> myfunc()
4
8
4
- wging 13y agoThis SyntaxErrors for me. >>> 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