read csv error question

Discussion in 'Python' started by rdmurray@bitdance.com, Feb 23, 2009.

  1. Guest

    Vincent Davis <> 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.

    --RDM
    , Feb 23, 2009
    #1
    1. Advertising

  2. John Machin Guest

    On Feb 24, 10:42 am, wrote:
    > Vincent Davis <> 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.
    >
    > --RDM


    A CSV file is *NOT* a text file. See the module docs. Also see this:
    http://bugs.python.org/issue4847
    John Machin, Feb 24, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    0
    Views:
    623
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    686
    Skip Montanaro
    Feb 13, 2004
  3. jliu66
    Replies:
    0
    Views:
    483
    jliu66
    Oct 19, 2007
  4. Li Chen
    Replies:
    18
    Views:
    637
    Azmi Farih
    Mar 23, 2010
  5. Sacha Rook

    csv read clean up and write out to csv

    Sacha Rook, Nov 2, 2012, in forum: Python
    Replies:
    2
    Views:
    197
    Hans Mulder
    Nov 2, 2012
Loading...

Share This Page