Dynamic function calls in Python using XMLRPC

I am writing a class that I intend to use to create subroutines, a constructor as shown below:

def __init__(self,menuText,RPC_params,RPC_call):
   #Treat the params
   #Call the given RPC_call with the treated params

      

The problem is I want to call a function in the rpc.serve template . (function name here) (params) "where rpc is the serverProxy object that I use to call XMLRPC functions, and serve.-function is the method that I call on the XMLRPC server.

I looked at calling a function from a function name string in Python , but seeing as my serverProxy object doesn't know what "removed attributes" it has, I can't use getattr () to retrieve the method.

I saw an example creating a dictionary to call a given function, but isn't there a way to make the function truly dynamic by creating a function call, since you would create a string? How do I run a String as a function?

+1


a source to share


1 answer


You can use getattr

to get the function name from the server proxy, so calling this function will work:



getattr(rpc, function_name)(*params)

      

+2


a source







All Articles