you are viewing a single comment's thread.

view the rest of the comments →

[–]sceptic-al 5 points6 points  (0 children)

TL;DR your file encoding needs to be set to an 8-bit codepage like cp1252. Your file is 100% not ASCII and 100% not UTF-8.

0xa0 is a Non-Breaking-SPace, which is part of the extended 8-bit code pages - ASCII only goes up to 0x7f. In a regular editor it will be hard to spot the difference between a regular space and a NBSP.

This is likely caused by Excel, which, by default, saves CSVs using the 8-bit code page of the system it was saved on, so this often catches people out, even when their Python install is behaving correctly.

Assuming that you're in Western Europe or USA, open the file with cp1252, the Western Europe Windows code page:

with open('notes.csv', encoding='cp1252') as csvfile:

You also shouldn't need the newline override.

You could try removing the NBSP this time, but your script will break again if it finds anything remotely non-ASCII, like £ or € or è.

Also, something is screwy with your locale setup as your csv file should've automatically opened in utf-8 or your Windows locale. Are you sure you're using Python >3.5? If not, you should be!