5
I am learning python3 and ended up getting stuck in the question of reading a simple csv file that contains the character 'à'. I’ve tried using Code, I find that I found through the internet but nothing seems to work, it is always printed as ' xc3 xa0'. Remembering that I use the sublime to edit the code and run it.
import csv
with open('teste.csv', 'r') as ficheiro:
reader = csv.reader(ficheiro, delimiter=';')
for row in reader:
print(row)
The test.csv file:
batata;14;True
pàtato;19;False
papa;10;False
The mistake:
Traceback (most recent call last):
File "/Users/Mine/Desktop/testando csv.py", line 5, in <module>
for row in reader:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
[Finished in 0.1s with exit code 1]
I’m waiting for help.
I’ve tried it before and it’s still the same mistake.
– Lucas Fabio
@Lucasfabio updated the answer, see if it solves
– Guilherme Nascimento
Really this is strange not to be working, expimenta put also this suggestion Guilherme, http://ideone.com/D8LF9o not to use the module csv... I doubt it’s that but no Lucas loses nothing in trying
– Miguel