I deal with a lot of people that prefer to open reports in Microsoft Excel. I've gotten used to generating CSV (comma separated value) files in Python for these folks. Ever so often, someone sends me a CSV file they have created via Excel. Invariably, I will get the following error when trying to read that file with Python:
_csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
This is annoying, but the solution to the problem is to open the file with universal newline mode enabled. This means using the mode 'U' or 'rU' in your open() function call. For example:
reader = csv.reader(open("data.csv", 'rU'), dialect='excel')
According to the open() documentation, universal newline mode accepts \n, \r, and \r\n as valid newline characters.

thanks, that was helpful :)
Thank you, so straightforward.
I'm working on a pretty complex script for exporting several videos at once, using a csv file to assign variables and configure the output videos. It also will include information as to the file location of the source videos, and where I want the output video saved to. These long files names that include '\n' (for events or people names that start with letter N), which throws off universal mode as a new line return. Question: In this case, should Libreoffice or OO spreadsheet tools, instead of excel, so I don't have to use Universal mode? Or is there a way to configure how I save the CSV to allow me to use it in another mode?
Justin -
Thanks for the question. This probably depends on what version of Excel you are using. I use Excel for Mac 2011 and I have the option of saving CSVs in MS-DOS or Windows modes.