我想将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.