Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eval function with parameters

Tags:

python

eval

I have three functions:

def function_1(arg_1, arg_1, arg_1, arg_1):
    return sol_1
def function_2(arg_1, arg_2, arg_3, arg_4):
    return sol_2
def function_3(arg_1, arg_2, arg_3, arg_4):
    return sol_3

And I would like to call them with a string:

myString = 'function_2'
eval(myString)

But I couldn't pass the arguments to the eval function to be passed to the custom defined function_2, as they are not homogeneous (np.array, float, float, int).

like image 342
fizcris Avatar asked Dec 06 '22 17:12

fizcris


1 Answers

Thak you Tim,

Everything had to be in string format, that worked.

eval(myString + '(arg_1, arg_2, arg_3, arg_4)')
like image 124
fizcris Avatar answered Dec 16 '22 09:12

fizcris