回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我试图将数据(主要是日期、布尔值和浮点数据类型)写入CSV文件格式。下面是我的代码片段:</p>
<pre><code># Write data to file
with open(OUTPUT_DIR + output_filename,'w') as outputfile:
wrtr = csv.writer(outputfile, delimiter=',', quotechar='"')
for x, y in datarows.items():
a,b,c,d,e,f,g = (somedate.strft('%Y-%m-%d'),0,6058.7,False,1913736200,0,False)
rowstr = "{0},{1},{2},{3},{4},{5},{6}".format(a,b,c,d,e,f,g)
wrtr.writerow(rowstr)
outputfile.close()
</code></pre>
<p>文件内容如下:</p>
<blockquote>
<p>2,0,0,7,-,10,-,03,",",0,",",6,0,5,8,.,7,",",F,a,l,s,e,",",1,9,1,3,7,3,6,2,0,0,",",0,",",F,a,l,s,e</p>
</blockquote>
<p>我目前正在使用raw file对象来写入文件-但是我更喜欢使用csvwrite-因为这正是它应该用来做的</p>