I have a string that contains a function name.
Using this string, how can I change the related function definition at run time?
This code updates the definition of the first function:
def first():
print("first")
def second():
print("second")
first = second
print(first)
print(second)
<function second at 0x7f35b40c3840>
<function second at 0x7f35b40c3840>
But that one doesn't:
def first():
print("first")
def second():
print("second")
func_to_change = "first"
eval_fist = eval(func_to_change)
exec('eval_fist = second')
print(eval_fist)
print(first)
<function second at 0x7f35b40c3a60>
<function first at 0x7f35b40c3840>