I have a special requirement where I am storing the python function code in a Table and fetching the same to be passed as argument and somehow call it and execute it.
For testing the same, I am trying to just check with a print statement if I can achieve the requirement. So here is how the code looks like.
rule_name, rule_string = fetch_rule_table('Rule_Table')
def func1(func):
# storing the function in a variable
res = func("Hello World")
print(res)
rule_string
func1(rule_name)
Now the variable rule_name
has the value bar
and variable rule_string
fetches the string which consists of the python function code, itself, which looks like below:-
def bar():
print("In bar().")
As the rule_string is just a string object, it cannot be call itself as the function, hence can somebody help here to get this working. the requirement is to save the rule function code in table and once fetched from table, we need to execute them as it is to get the required value.