0

I try to avoide to if or switch in python, but not sure if it is possible. For example, there are existing methods that can retrieve certain information, the name of each methods are

  • get_by_a
  • get_by_b
  • get_by_c

The formate to use those methods is like

output = client.get_by_a(**kwarg)

I am thinking to create a variable that represent the a, b, c part and the format will look like

variable = a
output = client.get_by_variable(**kwarg)

I cannot find a way to achieve it, any suggestion for this?

chun xu
  • 393
  • 1
  • 4
  • 13
  • You can include the variable name as a string into the method along with the other args and then utilize the other methods within that method based on the name string passed to it. – JBallin Oct 20 '22 at 05:22

0 Answers0