我運行下面的代碼,運行正常,當我硬編碼值「NoneType」對象有沒有屬性「得到」
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'
認罪se幫助
q = nse.get_quote(stock)返回None。檢查哪些nse_stocks可用。 – RvdK
'all_nse_stocks'看起來像什麼? – MattDMo
all_nse_stocks是一個包含INFY的文件 – user3198755