How to read latin caracters (Python)?

Viewed 71

I am learning to write code in Python. I've décided to write a program to increase smbs typing speed. That's why I've found several text documents to select random words from. I have a problem while reading the french file. It replaces 'é' caracters by '+AOK-'. I've searched for solutions for that issue, they said it was encryption problem. I've tried to change file encryption and to read as 'latin-1', but that did not work. I'm writing code in Pydroid, an IDE for Android.

2 Answers

Try reading the file as: df = pd.read_csv(filename,encoding = "ISO-8859-1")

ISO-8859-1 works well with Latin names

Have you tried using encoding='utf-8'? like this

with open('x.txt', 'r', encoding='utf-8') as f:
    print(f.read())
Related