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()

2 Answers 2

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)()
Sign up to request clarification or add additional context in comments.

5 Comments

actually instead of a and b could I write it as a="LinearKline.LinearKline_get"?
@tonyselcuk why don't you try it yourself and tell us!
I tried to do getattr(client, a)() but its giving me an error
maybe because a might not be a function.
a is a and b combined your function works I am just trying to make it simpler.
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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.