将行附加到csv文件Ruby 1.9 CSV lib [英] Append row to csv file Ruby 1.9 CSV lib

查看:147
本文介绍了将行附加到csv文件Ruby 1.9 CSV lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Ruby 1.9和CSV lib,我似乎不能添加一行。文档中的示例打开文件,并覆盖该行。

Using Ruby 1.9 and CSV lib, I can't seem to append a row. The example in the documentation opens the file, and overwrites the row. What is the correct way to append rows to the document?

文档中的示例:

require 'csv'
CSV.open("path/to/file.csv", "wb") do |csv|
  csv << ["row", "of", "CSV", "data"]
  csv << ["another", "row"]
  # ...
end


推荐答案

我想你可以改变开放使用 ab

I think you can change the open to use ab:

CSV.open("t.csv", "ab") do |csv|

这篇关于将行附加到csv文件Ruby 1.9 CSV lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆