我想在LED矩阵上每10秒显示当前汇率。但是,下面的代码似乎只能拉一次汇率,并每10秒重复一次。只有当我再次手动运行代码时,汇率才会更新。如何刷新API拉取请求?
from yahoofinancials import YahooFinancials
import time
yahoo_financials = YahooFinancials('EURCHF=X')
while True:
print yahoo_financials.get_current_price()
time.sleep(10)
而不是在第一行中调用API,您可以在每10秒钟的睡眠时间后在while循环中调用它。
from yahoofinancials import YahooFinancials
import time
while True:
yahoo_financials = YahooFinancials('EURCHF=X')
print yahoo_financials.get_current_price()
time.sleep(10)