0

I've tried various iterations of :encoding and options with no success. The file is created using the python csv module with the quote_all option turned on. It uses the default quote_char = '"' and the encoding = 'ascii'; I have matched these settings in the ruby script but I get the following error whenever I try to read in this file:

/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1894:in `block (2 levels) in shift': Missing or stray quote in line 1 (CSV::MalformedCSVError)
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1887:in `each'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1887:in `block in shift'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1849:in `loop'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1849:in `shift'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1791:in `each'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1805:in `to_a'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1805:in `read'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1411:in `block in read'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1354:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/csv.rb:1411:in `read'

Here is line 1 of the csv file:

"1","

Because line 2 starts with a newline

Looks like this might have something to do with the source file; toggling some options enlightened me on what the problem may be.

jcuwaz
  • 187
  • 3
  • 14
  • Why is this tagged `python`? Could you add a little more of the CSV (simplify/anonymise as necessary as long as the input keeps the same problem)? Having a more complete example may allow someone here to replicate your fault and suggest fixes. – Neil Slater May 11 '14 at 20:33
  • the file in question was created using a python script; maybe not a relevant tag; i will update with more of the csv – jcuwaz May 11 '14 at 20:34
  • 1
    what actually delimits one row from another row in this file? it's not newlines i take it. – nPn May 11 '14 at 21:43

1 Answers1

0

I want to provide the answer that worked for me: I was unknowingly omitting some key formatting directives by removing the headers. Adding them back allowed the file to parse normally but I didn't want the headers to be processed by the parser so I had to find an option for doing that without disrupting the csv gem and I found that here: https://stackoverflow.com/a/20623102/2964789.

Community
  • 1
  • 1
jcuwaz
  • 187
  • 3
  • 14