Python - Add to json list via Python

前端 未结 1 1321
温柔的废话
温柔的废话 2021-01-28 14:36

My json file

{
   \"people\": []
}

My python code

with open(\"people.json\") as jsonFile:
    load = json.load(jsonFile)
    d         


        
1条回答
  •  执笔经年
    2021-01-28 15:19

    You haven't written anything back into the file. Open up the file in write mode (open("people.json", r+)), then after you append the data, you'll need to json.dump the new dictionary into the file.

    Also, no need to do jsonFile.close() at the end. Your with statement deals with that.

    0 讨论(0)
提交回复
热议问题