Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pass contnets of variable instead of variable name

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading