I want to take written function (string) from a user input and convert it to a callable function in Python. How to achieve it despite any security concerns?
Example (string):
""" def test(): \n print('success') \n return 'success' """
I want to call / evaluate the said string by calling test() and make it print to the console.
value or func = eval(some code string), you might needvalue = func(params)afterwards.53.136, or(1, 2, 3), or{"x": 3}). You cannot parse function definitions with it.evalevaluates expressions; you needexecto execute adefstatement.