Ok I am not even sure the proper terminology to use to describe what I am trying to do. Anyway, I want to know if it is possible to programmatically or dynamically build a function call in python.
Let me explain.
I have a function inside a class that is defined with optional parameters like so:
class Agents(object):
def update(self, agent_id, full_name = "none", role = "none", status = "none"):
# do some stuff
So when I when I go to use that function, I may be updating just one, two or all 3 of the optional parameters. Sometimes it may be full_name and role but not status... or status and role but not name, or just status, or well you get the idea.
So I could handle this with a big block of if elif statements to account for all the permutations but that strikes me as really clumsy.
Currently I am calling the function like so:
an_agent = Agents()
an_agent.update(agent_id = r_agent_id)
Is there anyway to construct that function call programmatically, like appending the arguments to the call before making it. So that I can account for multiple scenarios like so:
an_agent = Agents()
an_agent.update(agent_id = r_agent_id, full_name = r_full_name)
or
an_agent = Agents()
an_agent.update(agent_id = r_agent_id, full_name = r_full_name, status = r_status)
Anyway, what is the best way to approach this?