[英]Append a new line to csv file using python
enter image description here I have a csv file and I want to append new lines to it when I used the code, the list didn't append to a new line, it appended the list to the last line of the csv file `在此处输入图像描述我有一个 csv 文件,当我使用代码时,我想要 append 新行,列表没有 append 到新行,它将列表附加到 csv 文件的最后一行`
List1=["test2"]
List2=["test1"]
with open (folder + '\\' + 'test.csv', 'a+', newline = '') as f_object:
writer_object = writer(f_object)
writer_object.writerow(List1)
writer_object.writerow(List2)
this is the output of the code这是代码的 output
Try this:尝试这个:
List1=["test2"]
List2=["test1"]
with open (r"Z:\Images\Test\test.csv", 'a+') as f_object:
writer_object = csv.writer(f_object)
writer_object.writerow(List1)
writer_object.writerow(List2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.