def getQuotesYahoo():
tickerStr = "GOOGL+AMZN"
yahoo_url ="http://finance.yahoo.com/d/quotes.csv?s=%s&f=saohgb3t1" % (tickerStr)
retQuotes = {}
data = urllib2.urlopen(yahoo_url).readlines()
for d in data:
p = d.strip().split(',')
stkInfo = {}
stkInfo['lastTime'] = p[6]
stkInfo['last'] = p[1]
stkInfo['open'] = p[2]
stkInfo['high'] = p[3]
stkInfo['low'] = p[4]
stkInfo['bid'] = p[5]
tic = p[0]
print stkInfo
retQuotes[tic] = stkInfo
print retQuotes['GOOGL']['last']
Bu kod, KeyError'da başarısız oluyor ve sözlüğü dize anahtarıyla doldurmuyor. Temelde googlefiance için çalışan aynı kod var.Python KeyError ile Başarısız Oldu
KeyError: 'GOOGL'
retQuotes:
{'"AMZN"': {'last': '594.60', 'bid': 'N/A', 'high': '597.86', 'low': '589.00', 'lastTime': '"4:00pm"', 'open': '594.32'}, '"GOOGL"': {'last': '759.98', 'bid': 'N/A', 'high': '767.13', 'low': '755.77', 'lastTime': '"4:00pm"', 'open': '765.87'}}
Google için hisse senedi senedi 'GOOGL' değil,' GOOG' – n1c9
'RetQuotes' içinde ne var? Değişkeni yazdırmak yardımcı olabilir. –
yapıda ticker gibi görünüyor. – user3763220