Hacker News new | ask | show | jobs
by icebraining 4740 days 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
1 comments

This 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