I am working on a Python script that needs to read data from a file containing non-ASCII characters. However, when I run my script, I encounter the following error message:
"UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 10: invalid continuation byte"
I have tried to specify the encoding of the file as "utf-8" using the following code:
with open('data.txt', 'r', encoding='utf-8') as f:
data = f.read()
Unfortunately, this still doesn't seem to work.
My expected outcome is to be able to read the data from the file without any errors and handle non-ASCII characters correctly.
Any help and suggestions would be greatly appreciated.
Edit:
data.txt
is as follows:
(for my french assignment)
Bonjour, comment ça va ?
Je suis en train d'apprendre le français.
J'aime bien écouter de la musique française.
Ça fait longtemps que je n'ai pas mangé de croissants frais.
Il y a beaucoup de sites web en français.
Je vais prendre un café au lait s'il vous plaît.
Les macarons sont délicieux.
Je rêve de visiter la Tour Eiffel un jour.
Le vin français est très bon.