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

时间:2015-10-19 15:34:35

标签: python csv

我正在尝试将一行3个数据点追加到现有的csv文件中。

library(SBMLR)
mapk <- readSBML("BIOMD0000000175.xml")
> summary(mapk)
Error in x$law(S0[c(x$reactants, x$modifiers)], x$parameters) : 
object 'membrane' not found

数据如下:

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)

原始CSV文件如下所示:

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

预计只需添加:

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

1 个答案:

答案 0 :(得分:1)

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)