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


Groups > comp.lang.python > #90291

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <somelauw@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'encoded': 0.07; 'python3': 0.07; 'similar,': 0.09; 'subject:Why': 0.09; 'python': 0.11; 'codec': 0.16; 'codecs': 0.16; 'ordinal': 0.16; 'subject:already': 0.16; 'subject:unicode': 0.16; "skip:' 30": 0.19; 'slightly': 0.19; '>>>': 0.22; 'import': 0.22; 'this?': 0.23; '&gt;&gt;&gt;': 0.24; 'byte': 0.24; 'this:': 0.26; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; '"",': 0.31; 'sep': 0.31; "skip:' 40": 0.31; 'subject:that': 0.31; 'file': 0.32; 'linux': 0.33; '(most': 0.33; 'skip:& 30': 0.33; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'subject:?': 0.36; 'skip:& 10': 0.38; 'nov': 0.38; 'to:addr :python-list': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'different.': 0.84; '\xe2\x82\xac': 0.84; '2013,': 0.91; '8bit%:18': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=kHjSzTKKleI7kin2B7N2Tdl+z/FXwCl3Lrmi2Z/ebO0=; b=ri8+6ob1doQjiOLRjHbduEOjR9vc468BsZke7/VWMpx3CV4BE00mYjK1Kp3EXKzOly Vq9enK490TKQyf6+0FP+dMegHhW9PJH4QGRy8k/7sobzegQKqUEitvo1HvW5Ub2PWMEC 6atKrFwtMVbe0TlV8Y5+glPx/on8pwP/QXGihIZsiOWN1qivyV6zDOfvYX5Y18WJ6uUn gOpCQIzNE9WIzWnvYoh9KfZGigytfnwfjDU+x0HJP0DwBicpgfQlAeYDN27BoUQJvOmA 2Bf8hUrsnj7rHZRi+Slqh6tAF3iLO3qJgySizuOLoIPuB5Rj8O3OU68DbytHfd83+xsQ 0R5Q==
MIME-Version 1.0
X-Received by 10.141.28.3 with SMTP id f3mr9096672qhe.37.1431273188498; Sun, 10 May 2015 08:53:08 -0700 (PDT)
Date Sun, 10 May 2015 17:53:08 +0200
Subject Why does unicode-escape decode escape symbols that are already escaped?
From "Somelauw ." <somelauw@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=001a1142340efa25210515bc4171
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.312.1431273197.12865.python-list@python.org> (permalink)
Lines 64
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431273197 news.xs4all.nl 2941 [2001:888:2000:d::a6]:38763
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90291

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

In Python 3, decoding "€" with unicode-escape returns 'â\x82¬' which in my
opinion doesn't make sense.
The € already is decoded; if it were encoded it would look like this:
'\u20ac'.
So why is it doing this?

In Python 2 the behaviour is similar, but slightly different.

$ 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'
>>>

$ python2 -S
Python 2.7.5+ (default, Sep 17 2013, 15:31:50)
[GCC 4.8.1] on linux2
>>> import codecs
>>> codecs.decode('€', 'unicode-escape')
u'\xe2\x82\xac'
>>> codecs.encode('€', 'unicode-escape')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0:
ordinal not in range(128)
>>>

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


Thread

Why does unicode-escape decode escape symbols that are already escaped? "Somelauw ." <somelauw@gmail.com> - 2015-05-10 17:53 +0200

csiph-web