我有以下代码:
try:
yf.Ticker("AALB.NV").history(period = "3mo")
except:
pass这给出了异常:- AALB.NV:找不到数据,符号可能会被摘牌。有没有什么方法可以捕获这个异常?
发布于 2020-12-01 08:55:08
如果符号无效,.history()函数不会引发异常,它只是将该语句打印到屏幕上。您可以自己引发异常:
import yfinance as yf
try:
data = yf.Ticker("AALB.NV").history(period="3mo")
if 'Empty DataFrame' in str(data):
raise Exception('Empty DataFrame - might be caused by an invalid symbol')
except Exception as e:
print(e)https://stackoverflow.com/questions/64865780
复制相似问题