I am studying using python decorator.
def my_dcrtr(fun):
def new_fun():
return fun()
return new_fun
I understand that the decorated fun function acts like a black box inside the decorator. I can choose to use fun () or not at all inside new_fun. However, I don't know if I can break into the “fun” and interact with an interesting local area inside new_fun?
eg. I am trying to make a game with remote procedural call (RPC) using python.
def return_locals_rpc_decorator(fun):
def decorated_fun(*args, **kw):
local_args = fun(*args, **kw)
return rpc_results
return decorated_fun
@return_locals_rpc_decorator
def rpc_fun(a, b, c=3):
return locals()
print(rpc_fun(2, 1, 6))
In this example, I am trying to get a list of rpc_fun arguments at runtime using the locals () command. Then send it to the server for execution. Instead of letting rpc_fun return its locals (), is it possible to use a decorator to retrieve the decorated function argument space?