I have a python file that reads a file given by the user, processes it, and ask questions in flash card format. The program works fine with an english txt file but I encounter errors when trying to process a french file.
When I first encountered the error, I was using the windows command prompt window and running
encoding='insert encoding type'
It's common question. Seems that you're using cmd which doesn't support unicode, so error occurs during translation of output to the encoding, which your cmd runs. And as unicode has a wider charset, than encoding used in cmd, it gives an error
IDLE is built ontop of tkinter's Text widget, which perfectly supports Python strings in unicode.
And, finally, when you specify a file you'd like to open, the
open function assumes that it's in platform default (per
sys.getdefaultencoding()). So if your file encoding differs, you should exactly mention it in keyword arg
open func. Alternatively you could call something like sys.setdefaultencoding('utf-8'), but be careful, it may break some poorly designed libs code used.