Mar-04-2019, 10:45 PM
Regarding security, I know that it is not absolutely safe. But IMO it's better to do something partly than do nothing.
I think that Stranac gave a good hint! Use the globals! Accordingly, the following code is functional and seems to be satisfying for my need:
Thank you for the help.
Olivier
I think that Stranac gave a good hint! Use the globals! Accordingly, the following code is functional and seems to be satisfying for my need:
import numpy symbol_table = numpy.__dict__.copy() symbol_table['__builtins__'] = None # remove built-in functions f = eval('lambda x:exp(1)', symbol_table)In my first post, I was not understanding the use of locals in the eval() function. I still do not understand exactly what it is meant to be used for, but I think that in the context of my question, the globals should be used.
Thank you for the help.
Olivier