【发布时间】:2015-06-27 13:57:29
【问题描述】:
我正在运行下面的代码,当我对值进行硬编码时运行良好
from nsetools import Nse
nse = Nse()
with open('all_nse_stocks') as nse_stocks:
for stock in nse_stocks:
q = nse.get_quote('INFY')
print q.get('open'), '\t', q.get('lastPrice'), '\t', q.get('dayHigh'), '\t', q.get('dayLow')
看到我已经硬编码了值 nse.get_quote('INFY') 但是当我运行以下代码时,出现以下错误:
from nsetools import Nse
nse = Nse()
with open('all_nse_stocks') as nse_stocks:
for stock in nse_stocks:
q = nse.get_quote(stock)
print q.get('open'), '\t', q.get('lastPrice'), '\t', q.get('dayHigh'), '\t', q.get('dayLow')
错误:
Traceback (most recent call last):
File "test.py", line 6, in <module>
print q.get('open'), '\t', q.get('lastPrice'), '\t', q.get('dayHigh'), '\t', q.get('dayLow')
AttributeError: 'NoneType' object has no attribute 'get'
请帮忙
【问题讨论】:
-
q = nse.get_quote(stock) 返回无。检查哪些 nse_stocks 可用。
-
all_nse_stocks长什么样子? -
all_nse_stocks 是一个包含 INFY 的文件