Re: Py3: Read file with Unicode characters

2010-04-08 Thread Gnarlodious
On Apr 8, 11:04 am, "Martin v. Loewis" wrote: > That's because you need to re-learn some things. Apparently so, every little item is a lesson. Thank you. -- Gnarlie -- http://mail.python.org/mailman/listinfo/python-list

Re: Py3: Read file with Unicode characters

2010-04-08 Thread Martin v. Loewis
Gnarlodious wrote: > 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

Re: Py3: Read file with Unicode characters

2010-04-08 Thread Gnarlodious
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') however I get error TypeError: Can't convert 'bytes' object to str implicitly I had assumed a Unicode string was a Unicode

Re: Py3: Read file with Unicode characters

2010-04-08 Thread Martin v. Loewis
Gnarlodious wrote: > Attempting to read a file containing Unicode characters such as ±: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position > 5007: ordinal not in range(128) > > I did succeed by converting all the characters to HTML entities such > as "±", but I want the charact

Py3: Read file with Unicode characters

2010-04-08 Thread Gnarlodious
Attempting to read a file containing Unicode characters such as ±: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 5007: ordinal not in range(128) I did succeed by converting all the characters to HTML entities such as "±", but I want the characters to be the actual font in th