+ 2

I have this letter 'à' in a file on python but when i read that file it print Ã\xa0

I have this letter 'à' in a file And when i open that using python it print Ã\xa0 How To solve it Thank you

2nd Jan 2020, 5:17 PM
iren yeger
iren yeger - avatar
7 Réponses
+ 5
Maybe your file is encoded with a charset different from utf-8. You can probably check it by opening it with a text editor such as notepad++ You might be able to open it correctly from python, if you specify the encoding= keyword argument for the open() function. Something like: with open('file.txt', 'r', encoding='latin_1') as file: print(file.read())
2nd Jan 2020, 6:34 PM
Tibor Santa
Tibor Santa - avatar
+ 3
Have you figured out the actual file encoding? It may be different from latin_1, is why I told you to check first. You can find a list of all encodings that python understand, here : https://docs.python.org/3/library/codecs.html#module-codecs
2nd Jan 2020, 6:47 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Tibor Santa Thank you it works But now the problem is with â It prints ä
2nd Jan 2020, 6:43 PM
iren yeger
iren yeger - avatar
+ 1
Tibor Santa Thank you
2nd Jan 2020, 6:48 PM
iren yeger
iren yeger - avatar
+ 1
I have had the same issues when I was using QPython3. For some reason, special letters were corrupted, although that *never* happened with regular desktop Python and the very same script. 🙄 I basically closed my eyes and hoped, the issue would disappear. Which it didn't.
2nd Jan 2020, 7:48 PM
HonFu
HonFu - avatar
+ 1
Ok then Thank you HonFu
2nd Jan 2020, 8:03 PM
iren yeger
iren yeger - avatar
+ 1
Hi Iren Yeger Do you have any update on this? I am experiencing the same error. What code made you fix this, if you did fix this? Kindest regards
11th Apr 2022, 1:28 PM
Jason