在Ruby中读取CSV的最佳方式。 FasterCSV? [英] Best way to read CSV in Ruby. FasterCSV?

查看:176
本文介绍了在Ruby中读取CSV的最佳方式。 FasterCSV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSV文件,我想用Ruby读取,并创建Ruby对象插入带有Active Record的MySQL数据库。什么是最好的方法做到这一点?我看到两个清楚的选项: FasterCSV & Ruby核心CSV 。哪个更好?有没有更好的选择,我错过了?

I have a CSV file that I want to read with Ruby and create Ruby objects to insert into a MySQL database with Active Record. What's the best way to do this? I see two clear options: FasterCSV & the Ruby core CSV. Which is better? Is there a better option that I'm missing?

编辑:Gareth说使用FasterCSV,那么什么是使用FasterCSV读取CSV文件的最好的方法?看看文档,我看到方法 parse foreach open ...它表示 foreach 用作读取CSV文件的主要接口。 。所以,我想我应该使用那个?

Gareth says to use FasterCSV, so what's the best way to read a CSV file using FasterCSV? Looking at the documentation, I see methods called parse, foreach, read, open... It says that foreach "is intended as the primary interface for reading CSV files." So, I guess I should use that one?

推荐答案

Ruby 1.9采用了FasterCSV 作为其核心CSV处理器,所以我会说,这绝对是更好的FasterCSV ,即使你仍在使用Ruby 1.8

Ruby 1.9 adopted FasterCSV as its core CSV processor, so I would say it's definitely better to go for FasterCSV, even if you're still using Ruby 1.8

这篇关于在Ruby中读取CSV的最佳方式。 FasterCSV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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