Why does unicode-escape decode escape symbols that are already escaped?

Terry Reedy tjreedy at udel.edu
Sun May 10 13:00:52 EDT 2015


On 5/10/2015 11:53 AM, Somelauw . wrote:
> In Python 3, decoding "€" with unicode-escape returns 'â\x82¬' which in
> my opinion doesn't make sense.

Agreed. I think this is a bug in that it should raise an exception 
instead. Decoding a string only makes sense for rot-13

> The € already is decoded; if it were encoded it would look like this:
> '\u20ac'.
> So why is it doing this?

> $ python3 -S
> Python 3.3.3 (default, Nov 27 2013, 17:12:35)
> [GCC 4.8.2] on linux
>  >>> import codecs
>  >>> codecs.decode('€', 'unicode-escape')
> 'â\x82¬'
>  >>> codecs.encode('€', 'unicode-escape')
> b'\\u20ac'

-- 
Terry Jan Reedy





More information about the Python-list mailing list