简体   繁体   English

将清单附加到CSV档案python中

[英]Append a list into a csv file python

I want to append a list into a csv file in python 我想将列表附加到python中的csv文件中

listoflist = [rhyme_cnt[row],gaali_cnt,diversity[row]]

This list contains three variables and the code I'm using to write this is 该列表包含三个变量,而我用来编写此代码的代码是

with open('C:/Users/Samarth/Desktop/Minor/songlyrics/final.csv',"ab") as output:
    writer = csv.writer(output,lineterminator = '\n')
    writer.writerows(listoflist)
    writer.writerows([])

But I'm getting the following error 但我收到以下错误

_csv.Error: iterable expected, not int

What am I doing wrong? 我究竟做错了什么?

I found the answer. 我找到了答案。 I had to change the writerows to writerow and change the open file method from 'ab' to 'a' 我不得不将写行更改为写行,并将打开文件方法从“ ab”更改为“ a”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM