Im new to Ruby programming. I got a job to create a program that can
obtain the content from a .csv file into .yml file. However at this
stage, im having trouble reading the .csv file. Here is the code i use:
#!/usr/bin/ruby
require ‘rubygems’
require ‘csv’
CSV.open(‘C:/Users/nizam/test_q.csv’, ‘r’) do |row|
p row
end
puts “Hello World”
Here is the error message i get:
<#CSV io_type:File io_path:“C:/Users/nizam/test_q.csv” encoding:UTF-8
lineno:0 col_sep:"," row_sep:"\n" quote_char:""">
Btw, im using Netbeans IDE 6.9.1 to write my script. I know this is just
a silly error but still cant figure it out. Hope some one can help.
Thanks
On Jan 11, 2011, at 4:07 PM, Kamarulnizam R. wrote:
Hai,
Hello.
Im new to Ruby programming.
Welcome.
puts “Hello World”
Here is the error message i get:
<#CSV io_type:File io_path:“C:/Users/nizam/test_q.csv” encoding:UTF-8
lineno:0 col_sep:"," row_sep:"\n" quote_char:""">
That’s not actually an error message. It’s an inspection of the CSV
object open() passed into your block. It looks like you were expecting
a row of data though, so switch open() to foreach() and that should get
you going.
C:/Ruby192/lib/ruby/1.9.1/csv.rb:1198:in delete': can't convert Symbol into String (TypeError) from C:/Ruby192/lib/ruby/1.9.1/csv.rb:1198:inforeach’
from C:/Ruby192/new_main.rb:9:in `’
I think it is because of the symbol in my csv file that cant be
converted. How to solve this so that i can read the whole document?
Please find the attached csv file.
One more thing, do think it is better for me to use the standard csv
library or faster csv library? As for my purpose to obtain data from csv
file and convert it into YAML file.
Thank you so much for a very quick reply. Appreciate that