read csv error question
sjmachin at lexicon.net
Tue Feb 24 09:07:50 CET 2009
On Feb 24, 10:42 am, rdmur... at bitdance.com wrote:
> Vincent Davis <vinc... at vincentdavis.net> wrote:
> > I am trying to read a csv file from excel on a mac. I get the following
> > error.SystemExit: file some.csv, line 1: new-line character seen in unquoted
> > field - do you need to open the file in universal-newline mode?
> > I was using the example code
> > import csv, sys
> > reader = csv.reader(open('/Volumes/vincentdavis
> > 2/match/data/matchdata2008.csv', "rb"))
> > try:
> > for row in reader:
> > print row
> > except csv.Error, e:
> > sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
> > I think this has to do with the end of line character but I am unsure how to
> > fix it. I don't what to change the actual csv file I would like to fix the
> > code.
> You could try reading the error message and looking at the documentation
> of the 'open' function. Pay particular attention to the keywords
> 'universal-newline mode'.
> Hint: 'rb' is almost the opposite of universal newline mode, and
> it is very rare that you'd want to use 'b' to read a text file.
A CSV file is *NOT* a text file. See the module docs. Also see this:
More information about the Python-list