I have a piece of code:
with open('filename.txt','r') as textfile:
kwList = [x.strip('\n') for x in textfile.readlines()]
I get a: UnicodeDecodeError : 'ascii' codec can't decode byte 0xc4 in position 5595: ordinal not in range(128) on line 2
The problem is that according the python docs : https://docs.python.org/3/library/functions.html#open
Python3 uses locale.getpreferredencoding(False)
to get the default encoding to use when there is no encoding specified in the open method.
When I run locale.getpreferredencoding(False), I get 'UTF-8'.
Why do I get 'ascii' codec failed in the UnicodeDecodeError when Python should use 'utf-8' to do this?