Py3: Read file with Unicode characters
Martin v. Loewis
martin at v.loewis.de
Thu Apr 8 19:04:38 CEST 2010
> On Apr 8, 9:14 am, "Martin v. Loewis" wrote:
>> When opening the file, you need to specify the file encoding.
> OK, I had tried this:
> open(path, 'r').read().encode('utf-8')
No, when *opening* the file, you need to specify the encoding:
open(path, 'r', encoding='utf-8').read()
> Sorry, doing Unicode in Py3 has really been a challenge.
That's because you need to re-learn some things.
More information about the Python-list