CSV module and Mac excel format problem

David Pratt fairwinds at eastlink.ca
Thu Oct 13 23:46:27 EDT 2005


Many thanks Andrew for this excellent piece of knowledge :-). 4 
characters of code and everything is great!

Regards,
David

On Friday, October 14, 2005, at 12:11 AM, Andrew McNamara wrote:

>> Hi. I have had good success with CSV module but recently came across
>> problem with reading excel from Mac Office.  The trouble is with line
>> endings.  Instead of \r\n you have just \r and the file as a whole
>> appears as a single line. CSV coughs and provides this exception:
>>
>> _csv.Error: newline inside string
>>
>> Saving as Windows (text) in Mac Office solves this but I don't
>> necessarily want to force users to save this way just to avoid
>> modifying my code. There is a lineterminator in the package.  Adding
>> parameter lineterminator='\r' did not correct the problem.
>
> Open the file in universal-newline mode - for example:
>
>     sample = open(filename, 'rU')
>
> "lineterminator" is only used for output - we use the supplied iterator
> (and whatever conventions it imposes) for input.
>
> -- 
> Andrew McNamara, Senior Developer, Object Craft
> http://www.object-craft.com.au/
>



More information about the Python-list mailing list