d1 = {
"a": "test"
}
cmd_dict = {
"cmd1": "d1['a']",
"cmd2 : "os.getcwd()"
}
value = eval(md_dict['cmd1])
print(value)
Not i will get the value as test.
I am getting pylint error W0123 becasue i am using eval. is there any way to perform the same without using eval.
Put functions in your dictionary, and you can simply call them like any other function. No
eval()needed:Note that
lambdacreates a small anonymous function that will evaluate and returnd1['a']when it's called; the delayed evaluation (which, again, you do not needeval()to do) is why it returnstesteven though that value is set ind1aftercmd_dicthas been created.