Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90299

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

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Why does unicode-escape decode escape symbols that are already escaped?
Date 2015-05-10 13:00 -0400
References <CA+gt_a82WGXHUZhcdbTUWG+TRV1Ys1ZSrkGjOxgavZGjAh9FiQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.319.1431277269.12865.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Why does unicode-escape decode escape symbols that are already escaped? Terry Reedy <tjreedy@udel.edu> - 2015-05-10 13:00 -0400
  Re: Why does unicode-escape decode escape symbols that are already escaped? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-11 14:00 +1000

csiph-web