python转csv_如何将Python元组转换为.csv文件?

我想将Python元组转换为.csv文件。假设我有一个retrieve()函数,当我用pprint打印它时,它是这样的:test = tuple(retrive(directory))

pprint(test, width=1)

然后:

^{pr2}$

所以,我用csv模块尝试了这个:with open('/Users/user/Downloads/output.csv','w') as out:

csv_out=csv.writer(out)

csv_out.writerow(['id','content'])

for row in test:

csv_out.writerow(row)

问题是我得到了一个奇怪的输出,看起来像这样:id,content

o,p,i,n,i,o,n,_,1,.,t,x,t,",", ,I, ,a,m, ,a,n, ,a,m,a,t,e,u,r, ,p,h,o,t,o,g,r,a,p,h,e,r, ,a,n,d, ,o,w,n, ,t,h,r,e,e, ,D,S,L,R, ,c,a,m,e,r,a,s, ,w,i,t,h, ,a, ,s,e,l,e,c,t,i,o,n, ,o,f, ,l,e,n,s,e,s,., ,H,o,w,e,v,e,r, ,t,h,a,t, ,c,o,l,l,e,c,t,i,o,n,

我怎么才能得到这样的东西:opinion_1.txt,I am an amateur photographer and own three DSLR c.... purchase

opinion_2.txt,This my second Sony Digital Came.... good camera for a good price!

opinion_3.txt,I ordered this camera with high hopes after couldn\\\'t find.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值