[MacRuby] #1103: csv.rb oddity
#1103: csv.rb oddity ---------------------------------+------------------------------------------ Reporter: percent20@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: csv ---------------------------------+------------------------------------------ Copied from mailing list: I am not sure if I am just doing something wrong or what, but I am trying to read in a CSV file and it seems the code I use for ruby 1.9.2 works fine, but not in MacRuby. I think I am doing something wrong, but not quite sure what since I am still new to MacRuby and getting familiar with it. I have put the following code in 'irb' and it works just fine and spits out the first part of the array. CSV.open('save.csv', 'r') do |row| puts row[1] end With irb I get smith smith smith using 'macirb' I get this. NoMethodError: undefined method `[]' for #<CSV:0x2005c9a20> /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/1.9.2/csv.rb:1340:in `open' Same code two different irb's My csv file has this in it: John,Smith,john@smith.com,1234567 John,Smith,john@smith.com,1234567 John,Smith,john@smith.com,1234567 Can someone point out to me what I am doing wrong? -- Ticket URL: <http://www.macruby.org/trac/ticket/1103> MacRuby <http://macruby.org/>
#1103: csv.rb oddity ---------------------------------+------------------------------------------ Reporter: percent20@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: csv ---------------------------------+------------------------------------------ Comment(by watson1978@…): {{{ $ cat test_csv.rb CSV.open('save.csv', 'r') do |row| puts row[1] end $ cat save.csv John,Smith,john@smith.com,1234567 John,Smith,john@smith.com,1234567 John,Smith,john@smith.com,1234567 $ ruby19 -v -r csv test_csv.rb ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0] test_csv.rb:2:in `block in <main>': undefined method `[]' for #<CSV:0x00000101180c98> (NoMethodError) from /usr/local/lib/ruby/1.9.1/csv.rb:1340:in `open' from test_csv.rb:1:in `<main>' $ irb19 irb(main):001:0> require 'csv' => true irb(main):002:0> CSV.open('save.csv', 'r') do |row| irb(main):003:1* puts row[1] irb(main):004:1> end NoMethodError: undefined method `[]' for #<CSV:0x00000101950590> from (irb):3:in `block in irb_binding' from /usr/local/lib/ruby/1.9.1/csv.rb:1340:in `open' from (irb):2 from /usr/local/bin/irb19:12:in `<main>' irb(main):005:0> $ ruby -v -r csv test_csv.rb ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] Smith Smith Smith }}} In my environment, test code works fine in the CRuby1.8, but even does not work in CRuby1.9. Is there an error in my procedure? -- Ticket URL: <http://www.macruby.org/trac/ticket/1103#comment:1> MacRuby <http://macruby.org/>
#1103: csv.rb oddity ---------------------------------+------------------------------------------ Reporter: percent20@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: csv ---------------------------------+------------------------------------------ Comment(by nagachika00@…): Hi Please try CSV.readlines instead of CSV.open -- Ticket URL: <http://www.macruby.org/trac/ticket/1103#comment:2> MacRuby <http://macruby.org/>
#1103: csv.rb oddity ---------------------------------+------------------------------------------ Reporter: percent20@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: Component: MacRuby | Keywords: csv ---------------------------------+------------------------------------------ Comment(by watson1978@…): Thank you, Nagachika-san! Indeed, it works when I use CSV.readlines. {{{ $ cat test_csv.rb CSV.readlines('save.csv').each do |row| puts row[1] end $ ruby -v -r csv test_csv.rb ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] Smith Smith Smith $ ruby19 -v -r csv test_csv.rb ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0] Smith Smith Smith $ macruby -v -r csv test_csv.rb MacRuby 0.9 (ruby 1.9.2) [universal-darwin10.0, x86_64] Smith Smith Smith }}} I watched a CSV library, but was about the same with CRuby1.9.2. (By encoding relations, there was a difference slightly.) -- Ticket URL: <http://www.macruby.org/trac/ticket/1103#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby