I’d like to define some contextual functions that can then be used later, as per the example below.
def add(x, y):
return x + y
def g(x):
u = my_func(x, 4 ** x)
return my_func(u, u // 2)
eval('g(1)', globals() | {'my_func': add})
This code throws NameError: name 'my_func' is not defined
. Is there any way to achieve this?