CSV.read Illegal quoting in line x

后端 未结 5 925
深忆病人
深忆病人 2020-12-08 04:16

I am using ruby CSV.read with massive data. From time to time the library encounters poorly formatted lines, for instance:

\"Illegal quoting in line 53657.\"         


        
5条回答
  •  旧时难觅i
    2020-12-08 04:54

    Apparently this error can also be caused by unprintable BOM characters. This thread suggests using a file mode to force a conversion, which is what finally worked for me.

    require 'csv'
    
    CSV.open(@filename, 'r:bom|utf-8') do |csv|
      # do something
    end
    

提交回复
热议问题