R
Rajarshi Guha
Hi ,
I have some code that generates a function on the fly in a string.
At a later point in time I want to execute this function (which also
requires a parameters to be passed to it). So the code is something like
this:
def generate_func():
s = """ def function(x):
print x
return 2
"""
return s
funcstring = generate_func()
retval = ....
That is, retval should have the value returned from the evaluation of the
function in the string funcstring.
Is this possible by means of simple function calls or does this involve
some sort of black magic?
Thanks,
I have some code that generates a function on the fly in a string.
At a later point in time I want to execute this function (which also
requires a parameters to be passed to it). So the code is something like
this:
def generate_func():
s = """ def function(x):
print x
return 2
"""
return s
funcstring = generate_func()
retval = ....
That is, retval should have the value returned from the evaluation of the
function in the string funcstring.
Is this possible by means of simple function calls or does this involve
some sort of black magic?
Thanks,