python 2.7 and unicode (one more time)

Michael Torrie torriem at gmail.com
Thu Nov 20 11:51:15 EST 2014


On 11/20/2014 09:32 AM, Peter Otten wrote:
> Chris Angelico wrote:
> 
>> On Fri, Nov 21, 2014 at 2:40 AM, Peter Otten <__peter__ at web.de> wrote:
>>> I think that you may get a Unicode/Encode/Error when you try to /decode/
>>> a unicode string is more confusing...
>>
>> Hang on a minute, what does it even mean to decode a Unicode string?
> 
> Let's not get philosophical ;)

It's not philosophical.  It's an important distinction that folks need
to be clear on when understanding unicode and the errors that python can
throw.

Unicode can only be encoded to bytes.
Bytes can only be decoded to unicode.

Without understanding that, the exception errors about decoding won't be
properly understood, nor will one know how to fix them.



More information about the Python-list mailing list