You could use the Python exec command to execute the code, but if any of
the code comes from users, this is a very bad idea, as any malicious code
(or even a mere mistake) could do a lot of damage.
Anthony
On Tuesday, August 28, 2012 11:36:54 PM UTC-4, lucas wrote:
>
> hello one and all,
>
> i want to store python code as a string in a text field of a table in a
> db, much like the code we write and store in a web2py view. at the right
> time, i want to compile the string into executed code and say the final
> line of the code be: "return = dict(...)". or after the code runs, its
> main variable would have the return variable contain the keys:values set
> that can be plugged into {{=xyz}} in a view type string. am i making sense
> because i am getting punchy from coding all day.
>
> so, i know about the render function to replace the {{=xyz}} in the view.
> however, how does web2py execute string into code, run it, and return the
> "return" variable that has the dictionary keys:values generated from that
> executed code?
>
> lucas
>
--