我正在尝试运行以下代码,但是当我运行最后一个块时,由于说没有找到这样的文件或目录而出错。
该错误发生在最后一块!
由于我对Python不太了解,所以不确定要尝试什么
def get_prices(share_symbol, start_date, end_date,
cache_filename='stock_prices.npy'):
try:
stock_prices = np.load(cache_filename)
except IOError:
share = Share(share_symbol)
stock_hist = share.get_historical(start_date, end_date)
stock_prices = [stock_price['Open'] for stock_price in stock_hist]
np.save(cache_filename, stock_prices)
return stock_prices.astype(float)
def plot_prices(prices):
plt.title('Opening stock prices')
plt.xlabel('day')
plt.ylabel('price ($)')
plt.plot (prices)
plt.savefig('prices.png')
plt.show()
if __name__ == '__main__':
prices = get_prices('MSFT', '1992-07-22', '2016-07-22')
plot_prices(prices)
FileNotFoundError Traceback(最近一次通话) 在get_prices(share_symbol,start_date,end_date,cache_filename)中 4尝试: ----> 5个stock_prices = np.load(缓存文件名) 6,除了IOError:
C:\ Users \ MRX \ Anaconda3 \ lib \ site-packages \ numpy \ lib \ npyio.py加载中(文件,mmap_mode,allow_pickle,fix_imports,编码) 第369回 -> 370 FID =打开(文件,“ rb”) 371 own_fid = True
FileNotFoundError:[错误2]没有这样的文件或目录:'stock_prices.npy'