我试图覆盖CSV中的列,但无法做到。在
import os
import csv
r=len(list(csv.reader(open('C:/Users/KaanPISI/Desktop/seyiresas.csv'))))
open('C:/Users/KaanPISI/Desktop/seyiresas.csv','w')
for i in range(0,r):
row[i] = row[i].write('/home/nvidia/racecar-ws/src/racecar-
controllers/deep_learning/data/057/',"%05d"%i,'.jpg')
i=i+1
这最终删除了CSV中的所有内容。在
不幸的是,我还没有找到使用
csv
模块覆盖CSV中的特定行的方法;您必须用新数据编写一个新文件(或覆盖现有文件,如下所示)。在在下面的代码中,我将CSV读入行列表(
lines
),然后您可以根据需要修改每个元素,然后删除CSV并在lines
中编写一个具有相同名称和修改数据的新元素。我使用with()
运算符,因为close()
是自动完成的。在您对打开的文件使用了错误的模式。你可以读到here
因此,当您设置
w
标志时,您将覆盖您的文件。您需要做的就是将w
更改为a
相关问题 更多 >
编程相关推荐