如何使用输入调用函数?

2024-05-12 22:05:19 发布

您现在位置:Python中文网/ 问答频道 /正文

如何打印以更改输入值

import cryptowatch as cw
time = input("Time:") #15m, 1h , 1d
x = cw.markets.get("KRAKEN:ATOMEUR", ohlc = True, periods = [time])
print(x.of_15m[1][4]))

例如:

time = input("Time:") #1h
print(x.of_1h[1][4])

或:

time = input("Time:") #1d
print(x.of_1d[1][4])

编辑: 我留下更多的信息

cryptowatch-sdk

https://github.com/cryptowatch/cw-sdk-python

函数所在的模块文件:(第255行)

https://github.com/cryptowatch/cw-sdk-python/blob/master/cryptowatch/resources/markets.py


Tags: ofhttpsimportgithubcominputgettime
1条回答
网友
1楼 · 发布于 2024-05-12 22:05:19

因为我没有安装cryptowatch,所以我无法真正正确地测试它,但我认为它可以工作。它使用用户的输入确定x对象属性的名称,然后使用getattr()检索其当前值

import cryptowatch as cw

time = input("Time:")
x = cw.markets.get("KRAKEN:ATOMEUR", ohlc=True, periods=[time])

interval = getattr(x, 'of_'+time, None)
if interval is not None:
    print(interval[1][4])
else:
    print('Error: unknown time', time)

相关问题 更多 >