简体   繁体   English

使用 Python csv writer 附加到 csv 文件的问题

[英]Issues with appending on to csv file with Python csv writer

I am trying to append on a row of 3 data points to an existing csv file.我正在尝试将一行 3 个数据点附加到现有的 csv 文件。

import time
import csv
data = [[time.strftime("%m/%d/%Y"), 10, 122]]

with open('C:\myfile.csv', 'a') as f:
    writer = csv.writer(f)
    writer.writerows(data)

The data comes out like this:出来的数据是这样的:

1   0   /   1   9   /   2   0   1   5
<blank row>                             
10/19/2015  10  122                         
<blank row>                             
10/19/2015  10  122                         

The original CSV file looked like this:原始 CSV 文件如下所示:

10/17/2015  120  22
10/18/2015  110  2

Expected to just add this:预计只添加这个:

10/19/2015  10  122 
import time
import csv
data = [[time.strftime("%m/%d/%Y"), 10, 122]]

with open('C:\myfile.csv', 'a', newline = '') as f:
    writer = csv.writer(f)
    writer.writerows(data)

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

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