I have this code
response = sf.list_state_machines(maxResults=2)
I want to:
- make list_state_machines as a passed in argument to the function – named action_cmd
- make maxResults=2 be a passed in argument to the function – named payload
then I can do the following
response = sf.action_cmd(payload)
this does not work, of course. How do I pass these variables so sf recognizes contents of action_cmd as the name of the command and passes the contents of payload as input to the function?
I have no control over the function I am calling
>Solution :
better to use a wrapper function,I will give you an example, in my example action_cmd is a wrapper function that takes the command and payload as arguments
check this out :
def action_cmd(command, **kwargs):
if command == "list_state_machines":
return sf.list_state_machines(**kwargs)
#add your conditions for other commands
#you can use it like this
command = "list_state_machines"
payload = {"maxResults": 2}
response = action_cmd(command, **payload)