首先导入库:import csv
- 读文件
with open(filename) as fp:
f_tsv = csv.reader(fp, delimiter=',')
for line in f_tsv:
print(line)
- 写文件
with open(filename, 'w') as fw:
writer = csv.writer(fw)
writer.writerow(['X', 'Y', 'Z', filename, 'period:' + str(number)]) #一行
writer.writerows(data[start:end, :]) #多行