Re: read csv error question
On Feb 24, 10:42 am, rdmur...@bitdance.com wrote: Vincent Davis vinc...@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. --RDM A CSV file is *NOT* a text file. See the module docs. Also see this: http://bugs.python.org/issue4847 -- http://mail.python.org/mailman/listinfo/python-list
Re: read csv error question
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. FYI, Mac line endings are carriage-return '\r', Linux line endings are linefeed '\n', and Windows endings are _both_ '\r\n'. Try: reader = csv.reader(open('/Volumes/vincentdavis 2/match/data/matchdata2008.csv', U)) # or rU This will open the file for reading with universal line ending support, which will accept any kind of these line endings. (Opening it in text mode r should also work, assuming that the .csv file does indeed have the correct line endings for that platform.) -- http://mail.python.org/mailman/listinfo/python-list
Re: read csv error question
On Mon, Feb 23, 2009 at 6:43 PM, MRAB goo...@mrabarnett.plus.com 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. FYI, Mac line endings are carriage-return '\r', Linux line endings are linefeed '\n', and Windows endings are _both_ '\r\n'. Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is Unix-based so it uses line feeds. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: read csv error question
Thanks for the help the U was what I needed. I was reading the documentation here.http://docs.python.org/library/csv.html but I could not find the term universal-newline mode, In fact where do you find U I have not read it word for word but it is not obvious to me. I do even see anything about rb but I might just be really blind. Thanks again Vincent Davis On Mon, Feb 23, 2009 at 4:52 PM, Benjamin Kaplan benjamin.kap...@case.eduwrote: On Mon, Feb 23, 2009 at 6:43 PM, MRAB goo...@mrabarnett.plus.com 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. FYI, Mac line endings are carriage-return '\r', Linux line endings are linefeed '\n', and Windows endings are _both_ '\r\n'. Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is Unix-based so it uses line feeds. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: read csv error question
I just thought to look in the documentation for open() It seems this may contain the answers to my questions. I am just to new to python to know where my problem is, Thanks Vincent Davis 720-301-3003 On Mon, Feb 23, 2009 at 4:52 PM, Benjamin Kaplan benjamin.kap...@case.eduwrote: On Mon, Feb 23, 2009 at 6:43 PM, MRAB goo...@mrabarnett.plus.com 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. FYI, Mac line endings are carriage-return '\r', Linux line endings are linefeed '\n', and Windows endings are _both_ '\r\n'. Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is Unix-based so it uses line feeds. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: read csv error question
Benjamin Kaplan wrote: On Mon, Feb 23, 2009 at 6:43 PM, MRAB goo...@mrabarnett.plus.com mailto:goo...@mrabarnett.plus.com 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. FYI, Mac line endings are carriage-return '\r', Linux line endings are linefeed '\n', and Windows endings are _both_ '\r\n'. Just to clarify, only the old Mac OSes (1-9) use carriage returns. OS X is Unix-based so it uses line feeds. Slightly OT, but PPD files on Macs used to work whatever the line endings (as they should, according to the spec), but at some point on MacOS X they broke that and PPD files would work only with CR line endings. I don't know if they've fixed that. Anyway, although it's Unix underneath I'm not so sure that they don't use CR line endings elsewhere for backwards compatibility. -- http://mail.python.org/mailman/listinfo/python-list