I have the following code in Python 3, which is meant to print out each line in a csv file.
import csv
with open(\'my_file.csv\', \'r\', newline=\'\') as csv
For others who hit the same error shown in the subject, watch out for the file encoding of your csv file. Its possible it is not utf-8. I just noticed that LibreOffice created a utf-16 encoded file for me today without prompting me although I could not reproduce this.
If you try to open a utf-16 encoded document using open(... encoding='utf-8')
, you will get the error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
To fix either specify 'utf-16' encoding or change the encoding of the csv.