By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,995 Members | 1,217 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,995 IT Pros & Developers. It's quick & easy.

CSV module and Mac excel format problem

P: n/a
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.

The way I am reading tab delimited to dictionary:

lines = sample.readlines()
headers = csv.reader(lines, delimiter='\t').next()
rows = csv.DictReader(lines, headers, delimiter='\t')
for row in rows:
print row

Regards,
David
Oct 14 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.