python json data リストの複数の値を取り出ししたいのですがエラーになってしまします。
単純に-2,-3などとカンマで切っても構文エラーになってしまします。-2 and -3 でも構文エラーでした。
import requests from datetime import datetime # CryptowatchのAPIで1分足を取得 response = requests.get("https://api.cryptowat.ch/markets/bitflyer/btcfxjpy/ohlc?periods=60") response = response.json() # 最後から2番目の情報を取り出す data = response["result"]["60"][-2]←この部分の情報を複数取り出したいです close_time = datetime.fromtimestamp(data[0]).strftime('%Y/%m/%d %H:%M') print(data[-2])
data = response["result"]["60"][-2,-3]
エラーコード
TypeError: list indices must be integers or slices, not tuple
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/08 04:27
2018/07/08 04:41
2018/07/08 05:02
2018/07/08 05:50 編集