Hello Guys, May be it is simply but any way.... fasterCSV 1.2.0 how to load data from file to table :( I have tried this: file has just one line 1,2,3 data = FCSV.read("C:\\temp_file.csv") table = FCSV.parse(data, :headers => true) puts "data overview" puts data puts "table overview" puts table but got very strange error: undefined method `pos'' for #<Array:0xcb2e114> (<-- this is for another big file) for file with 1,2,3 it shows: undefined method `pos'' for [["1", "2", "3"]]:Array What is reason and what is the "pos"? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Have tried this way... data = FCSV.read("C:\\temp_file.csv") csv_output = FasterCSV.generate do |csv| data.each do |dt| csv << dt end end table = FCSV.parse(csv_output, :headers => true) but does it really good way? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can use FasterCSV: data = [] FasterCSV.foreach(''file.csv'') { |row| data << row } puts data #data is all loaded now in the ''data'' variable Also, using the (slower) built in libraries: CSV::Reader.parse(string) { |row| row.each { |cell| puts cell }} Both these examples are from the really good O''Reilly book, Ruby Cookbook On Jul 25, 5:15 am, Vitali <vit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Have tried this way... > data = FCSV.read("C:\\temp_file.csv") > csv_output = FasterCSV.generate do |csv| > data.each do |dt| > csv << dt > end > end > > table = FCSV.parse(csv_output, :headers => true) > > but does it really good way?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- How Can I insert another column data into the CSV file when I use FasterCSV?
- installing fastercsv into vendor directory
- newbie wants to know..FasterCSV or just CSV?
- fastercsv, freezing into vendor/gems
- How do I use fastercsv to just read the header row and not the whole file?