我得到了这个功能:
def restapuntos(precio, usuario ,saladondeocurre):
print("Function started")
data = []
with open("listas\estadisticas\Trivial-"+saladondeocurre+".txt", "r+") as f:
for line in f:
data_line = json.loads(line)
if data_line[0] == usuario:
print("User: "+user.name+", removing "+str(precio)+" from "+str(data_line[1]))
data_line[1] = data_line[1]-precio
data.append(data_line)
f.seek(0)
f.writelines(["%s\n" % json.dumps(i) for i in data])
f.truncate()
print("Function has been used")
被称为:
Myclass.restapuntos(10, user.name, room.name)
3张照片告诉我:
Function started
User: saelyth, removing 10 from 461
Function has been used
但问题是:文件没有更新,它仍然显示 461 而不是 451,尽管一切似乎都工作正常,打印实际上知道该怎么做没有错误,文件中的信息仍然与之前相同我运行代码。
有谁知道为什么?