I would like to read a file that contains french characters in Python such "é".I'm using these lines of code to do that:
import codecs
with codecs.open(r'C:UserschsafouaneDesktopsaf.txt', encoding='ascii') as f:
for line in f.readlines():
line
Yet, I get a
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 3: ordinal not in range(128)
To reproduce the error, the file I'm trying to read contains only one word: "Accélération". Is there a way to accomplish this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…