0
试图让添加新行的方法波纹管的界面如下:Python3 - CSV - 添加行与namedtuple
def row_add(self, **rowtoadd)
我不知道怎么样,如果我定义喜欢我列:
stuff1, stuff2, stuff3
我可以得到一个** namedtuple按正确的列名称顺序排序。
到目前为止,我已经试过(这里表=我们正在编辑的文件路径,包含我们需要的CSV):
def row_add(self, **rowtoadd):
if os.path.isfile(self.table):
with open(self.table, 'a') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(rowtoadd)
但namedtuple没有转化成一排,只有名字变量是。 例如:
row_add(stuff1="hello1", stuff2="hello2", stuff3="hello3")
cat ./my_file.csv -> stuff1, stuff2, stuff3