Dynamically loading Python application code from database under Google App Engine

前端 未结 3 2159
终归单人心
终归单人心 2020-12-29 14:14

I need to store python code in a database and load it in some kind of bootstrap.py application for execution. I cannot use filesystem because I\'m using GAE, so this is my o

3条回答
  •  天命终不由人
    2020-12-29 15:07

    I somewhat agree with the commentators above, it sounds kind of dangerous. However:

    I experimented a little with App Engine Console ( http://con.appspot.com/console/ ), and eval() indeed tended to throw SyntaxError's.

    Instead, the exec statement might be your friend ( http://docs.python.org/release/2.5.2/ref/exec.html ).

    I managed to run this in App Engine Console:

    >>> exec "def f(x):\n    x = x + 1\n    y = 10\n    return x + y"
    >>> f(10)
    21
    

    So try the exec statement, but remember the many, many (many!) perils of code coming directly from end-users.

提交回复
热议问题