擅长:python、mysql、java
<p>写入后需要截断文件:</p>
<pre><code> def removeUserFunc(SID):
print(SID.get())
with open('Credentials.json','r+') as json_file:
data = json.load(json_file)
data['Credentials'][:] = [item for item in data['Credentials'] if item['username'] != SID.get()]
json_file.seek(0)
json.dump(data,json_file,indent=3,sort_keys=True)
json_file.truncate()
</code></pre>