Changing The Structure Of A Function With If Statement Python
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 bot
Solution 1:
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)()
Solution 2:
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()
Post a Comment for "Changing The Structure Of A Function With If Statement Python"