我正在将用户数据保存到CSV文件。当我尝试更新用户信息时,信息会正确更新,但它还会复制最后一行的最后几个字符,创建新行并将其粘贴。
这是我的代码
(索引和新索引是列表行中两个不同用户的索引)
with open(filename,'r+',newline='') as f:
reader = csv.reader(f)
lines = list(reader)
with open(filename,'r+',newline='') as f:
writer = csv.writer(f)
lines[index][3]= inv
lines[index][2] = money
lines[newindex][2] = sellermoney
lines[newindex][8] = shopitems
writer.writerows(lines)
f.close()
提前致谢
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句