L
L
LordOftheCode2021-11-23 21:33:31
Python
LordOftheCode, 2021-11-23 21:33:31

Why are the wrong python values ​​being added to the json file?

My code:

logpass = []
    infuser = {}
    infuser[logpass[0]] = {
        'login': logpass[1],
        'password': logpass[2]
    }
    testlist.append(infuser)

    with open('accounts.json', 'w', encoding="utf-8") as f:
        json.dump(testlist, fp=f, ensure_ascii=False, indent=4)


I get the values ​​​​from the telegram and write the value to the list and write the list to the json file, the 1st time when I add it correctly adds, then I add the sheet 2 times and overwrite the json file, but the past value is entered there again, I can’t understand it how did i make a mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CleanyBoom, 2021-11-23
​​@CleanyBoom

If this happens several times in a row in one run, the problem is most likely that the logpass is not cleared, and the values ​​\u200b\u200bthat were there before are still used

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question