我想每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)
发布于 2019-09-30 09:42:51
相反,在第一行调用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)
https://stackoverflow.com/questions/58172723
复制