Well I have a file containing unicode "û". This is however not read correctly as shown in the following test case:
print("û")
with open(r"testfile.txt") as f:
for line in f:
print(line)
Which outputs:
û
û
The IDE can correctly display the character - yet from reading the file another character is shown.
If I execute it in the debugger I see that f has as "encoding" cp1252. Not unicode.
So how would I "fix" this?
Opening the file in notepad++ tells me the file really is UTF-8. If I manually change the file to be windows-codepage 1252 it seems to work. But that's not really what I want.
openuses the encoding returned bylocale.getpreferredencodingwhich basically defaults to cp1252 on windows.