0

There is the function a could either be in the form of client.LinearKline.LinearKline_get() or in the form of client.Kline.Kline_get(). How could I make a and b modular so that both options could work the function below does not really work.

if choice ==1:
    a= LinearKline
    b= LinearKline_get
else:
    a= Kline
    b= Kline_get

client.a.b()
tony selcuk
  • 709
  • 3
  • 11

2 Answers2

3

you can also use getattr for this.

if choice == 1:
    a = "LinearKline"
    b = "LinearKline_get"
else:
    a = "Kline"
    b = "Kline_get"

getattr(getattr(client, a), b)()
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
jen
  • 199
  • 1
  • 5
1

If you have access to the client variable you can directly pick the function you need to call:

if choice == 1:
    f = client.LinearKline.LinearKline_get
else:
    f = Kline.Kline_get

f()
quamrana
  • 37,849
  • 12
  • 53
  • 71