2

I was trying to get an idea of some lines in a huge csv file so I did this

with open('###.csv','rb')` as csvfile:
    conusreader = csv.reader(csvfile,delimiter=' ', quotechar='|')
    for row in conusreader:
        print ', '.join(row)

Then I got an error in Pycharm

"for row in conusreader: _csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?"

I'm not quite sure what it means. Could anyone help me to fix this error?

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
Kailin Huang
  • 45
  • 1
  • 5
  • 1
    Could you gave a small example of your csv file? – Martin Evans Jun 28 '15 at 18:40
  • The error is implying you need to try using something like this: `csv.reader(open(csvfile, 'rU'), delimeter=' ', quote='|')`. Which operating system are you running this on? – Martin Evans Jun 28 '15 at 19:19
  • Hi Martin. I use OS X Yosemite and IDE is Pycharm. a line of the file looks like this (geospatial data) "GA 13215 Muscogee County 1 Columbus -84.8769 32.51 250 -85.0262 32.608 -85.0228 32.6079 -85.0216 32.6079 -85.0154 32.6078 -84.9818 .......". – Kailin Huang Jun 28 '15 at 20:53
  • I tried what you wrote and got the same error... – Kailin Huang Jun 28 '15 at 20:53
  • Do you get any output or does this fail on the first loop? Consider loading the file into an editor to try and spot what is triggering the fault. Consider using a hex editor to spot 0x0D 0x0A characters in the csv file. – Martin Evans Jun 28 '15 at 21:20
  • check it here http://stackoverflow.com/questions/17315635/csv-new-line-character-seen-in-unquoted-field-error – Haifeng Zhang Jun 01 '16 at 05:08

0 Answers0