api电话
from rtstock.stock import Stock
stock = Stock('AAPL')
data = stock.get_latest_price()
print(data)
yeilds
[{'LastTradeTime': '2:54pm', 'LastTradePriceOnly': '119.855'}]
我正在尝试使用
打印119.855
没有撇号
from rtstock.stock import Stock
stock = Stock('AAPL')
data = stock.get_latest_price()
print(data['LastTradePriceOnly'])
并收到错误消息
print(data['LastTradePriceOnly'])
TypeError: list indices must be integers or slices, not str
感谢任何帮助,谢谢!!
答案 0 :(得分:3)
data是包含单个字典的列表:
data = [{'LastTradeTime': '2:54pm', 'LastTradePriceOnly': '119.855'}]
print(data) # list containing a dictionary
print(data[0]) # the dictionary
print(data[0]['LastTradePriceOnly']) # 119.855