1
我正在使用Google財務模塊來獲取Python中的庫存數據。我想從列表中分離出LastTradePrice並將其轉換爲整數。有什麼建議麼?謝謝。在Python列表中分離字符串
from googlefinance import getQuotes
import json
stockinfo = getQuotes('VSMGX')
stockdata = json.dumps(stockinfo, indent=1)
的stockdata看起來像這樣
[
{
"ID": "904726512134516",
"LastTradeDateTimeLong": "Jan 8, 4:00PM EST",
"Index": "MUTF",
"LastTradeWithCurrency": "$22.26",
"LastTradeTime": "4:00PM EST",
"StockSymbol": "VSMGX",
"LastTradePrice": "22.26",
"LastTradeDateTime": "2016-01-08T16:00:00Z"
}
]
你真的想要它是一個整數? '22.26'會回到'22'。 '[float(d ['LastTradePrice'])對於股票數據中的任何錯誤''。 BTW'info1'不存在 - 你的意思是'stockinfo'嗎? – AChampion
是的,我應該使用浮動。謝謝!你的回答起作用 –
糟糕,我只是寫了與@AChampion相同的代碼,令牌令牌!那麼它是一個成語:-) – alexis