jsonファイルを読み込んで特定の要素を削除したい。
test.pyファイル
python
1import json 2 3f= open('./json/20171105-000617.json', 'r') 4result = json.load(f) 5print(result) 6del result[0]['faceRectangle'] 7print(result)
出力結果
# python test.py [ { "faceId": "XXXXXXXXXXXXXXXXXXXXXx", "faceRectangle": { "width": 179, "top": 113, "height": 179, "left": 181 }, "faceAttributes": { "gender": "male", "age": 17.1 } } ] Traceback (most recent call last): File "test.py", line 6, in <module> del result[0]['faceRectangle'] TypeError: 'unicode' object does not support item deletion
faceRectangleの要素を削除してprintしたいのですが失敗しています。
del文はスクリプト内では使えないのでしょうか??
ご教示お願い致します。
回答2件
あなたの回答
tips
プレビュー