0
我的紅寶石版本中運行下面的代碼1.8.7意外「:」和意外「)」錯誤
require 'csv'
FILENAME = 'filename'
cleansed_output = File.open('filename_cleaned.csv','wb')
CSV.open(FILENAME, encoding: 'ISO8859-1') do |output|
row_number = 1
loop do
begin
break unless row = output.shift
cleansed_output << row.to_csv
rescue CSV::MalformedCSVError => e
puts "Malformed row #: #{row_number}"
ensure
puts "Row number: #{row_number}" if row_number % 10000 == 0
row_number += 1
end
end
end
cleansed_output.close
和我得到了以下錯誤:
csv_cleanser2.rb:7: syntax error, unexpected ':', expecting ')'
CSV.open(FILENAME, encoding: 'ISO8859-1') do |output|
^
csv_cleanser2.rb:7: syntax error, unexpected ')', expecting $end
CSV.open(FILENAME, encoding: 'ISO8859-1') do |output|
我試圖用分隔符來清理csv。任何人都知道問題在這裏?
謝謝!
啊,我們有走。這固定了第一部分,但現在我得到了另一個奇怪的錯誤: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/csv.rb:89:in'open ':'mode'必須是'r','rb','w'或'wb'(ArgumentError) \t from csv_cleanser2.rb:7 我正在使用'wb',那麼爲什麼這會給我一個錯誤?另一個版本問題? – jstauss