I've been recently trying with some program synthesis. Here, I'm generating strings, that represent valid functions. My current solution includes printing the string to stdout, storing them to a file, and calling that file from somewhere else. However, can the functions be directly imported into a given namespace? Assume the following example:
def sum2(x):
return sum(x)
print(sum2([1,2,3]))
sstring = """
def sum3(x):
return sum(x)
"""
eval(sstring)
print(sum3([1,2,3]))
Is anything like the second part (which does not work) possible? Is eval() limited to primitive expressions?