On 21/08/21 6:15 am, Hope Rouselle wrote:
code()
'def p():\n  import math\n  return math.e\n'
exec(code())
p
<function p at 0x0113F5D0>
p()
2.718281828459045

Note that this pollutes the globals of the module that you're calling
exec() from. For better isolation you can pass in an explicit globals
dict:

g = {}
exec(code(), g)
g['p']()

--
Greg

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to