Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90303
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <fomcl@yahoo.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'encoded': 0.07; 'python3': 0.07; 'cest': 0.09; 'similar,': 0.09; 'strings.': 0.09; 'subject:Why': 0.09; 'to)': 0.09; 'python': 0.11; '2.7.2': 0.16; '4.9': 0.16; '>in': 0.16; '>the': 0.16; 'codec': 0.16; 'codecs': 0.16; 'skip:> 20': 0.16; 'subject:already': 0.16; 'subject:unicode': 0.16; 'wrote:': 0.18; 'slightly': 0.19; '>>>': 0.22; 'import': 0.22; 'this?': 0.23; 'byte': 0.24; 'unicode': 0.24; 'header:Received:8': 0.24; 'this:': 0.26; 'to:2**1': 0.27; 'to:no real name:2**1': 0.29; "doesn't": 0.30; "skip:' 10": 0.31; '"",': 0.31; 'sep': 0.31; 'subject:that': 0.31; 'file': 0.32; 'linux': 0.33; '(most': 0.33; "can't": 0.35; 'but': 0.35; 'skip:> 10': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'skip:- 20': 0.37; 'nov': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'received:67.195': 0.60; 'received:98.137': 0.60; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; '2014,': 0.84; '2015': 0.84; 'different.': 0.84; 'received:bullet.mail.gq1.yahoo.com': 0.84; '\xe2\x82\xac': 0.84; '2013,': 0.91 |
| X-Yahoo-Newman-Property | ymail-4 |
| X-Yahoo-Newman-Id | 278340.62132.bm@omp1004.mail.gq1.yahoo.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1431283174; bh=wuRGV5hfiptD9vU5J4dcAYQ1mYvvZatPgo6nAkDlFLg=; h=Message-ID:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=nGb2HgQ0ey9W5CXvxbo0AS9hzZa/UHyBZySCQ/7dbFh/lCxO6sbK7Goz5BC2bdkp6C4/CnVz9RsMpJKdYrN2ocGWTGj//RCtYgJ7ltF3EAcPeAcKyLhQR0ngsN4M/CEI0QI9VW+pWDuZcLycRSH+oEa5nEzVKx3x53I6GOHs/P0= |
| X-YMail-OSG | vuN8JIkVM1nhrPvchE.ey8icHE9Ne3IA6nU9fwPlOLdQJP_ Moj8is..sqBdENTLo4InMtBArjBKkO8q9yI6i5DBusKWVUTmoRiEffRLoRex C1dC48gCBxEV_1zfSCBwV7e81TIcfMhuZ5GX8GPUdC8l1pNaCd2IJwViyVeR maUzA3Xsz7aSHa5mexzP2WYFUj5Tt357h5Fehuc.Vjy.1p8SXPyZMaXSdweu B0RqIneVNd3o0bXfSOrpg5IMwl46VNtyetkdKqvOXgRla3PF5kXtnxiFGBH8 T8JInrNoQi.lzDf3FXsEuxCavDXNbxJ_rR.Pub2Fj_ge1WBhSDSum1GZpAGT MLoyi9oRQwA8WsORkTZGB4UTvWw8fkV9PJh6S_cduAOOTJsORz5BWp9RXOmC O4lVlxOPYGx3r6y7nWvCgTH63cY1ZZiOUSjpJq7x3_48td1T6vzD4.YV.g38 LZIyTevgRT522tUpIroGtMAsN5kDEraXhCX4qkENnwOs7Oj3UtkvwnvoYUPn u8p4h_nOqPPSLQ7ehwukthRdsDb88Clh5jBt1nsH4TdY2z7IhearKxTW2rkE u |
| X-Rocket-MIMEInfo | 002.001, Ci0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tDQpPbiBTdW4sIE1heSAxMCwgMjAxNSA1OjUzIFBNIENFU1QgU29tZWxhdXcgLiB3cm90ZToNCg0KPkluIFB5dGhvbiAzLCBkZWNvZGluZyAi4oKsIiB3aXRoIHVuaWNvZGUtZXNjYXBlIHJldHVybnMgJ8OiXHg4MsKsJyB3aGljaCBpbiBteQ0KPm9waW5pb24gZG9lc24ndCBtYWtlIHNlbnNlLg0KPlRoZSDigqwgYWxyZWFkeSBpcyBkZWNvZGVkOyBpZiBpdCB3ZXJlIGVuY29kZWQgaXQgd291bGQgbG9vayBsaWtlIHRoaXM6DQo.J1x1MjBhYycuDQo.U28gd2gBMAEBAQE- |
| X-Mailer | YahooMailWebService/0.8.203.740 |
| Date | Sun, 10 May 2015 11:39:34 -0700 |
| From | Albert-Jan Roskam <fomcl@yahoo.com> |
| Subject | Re: Why does unicode-escape decode escape symbols that are already escaped? |
| To | somelauw@gmail.com, python-list@python.org |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | quoted-printable |
| 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.323.1431283552.12865.python-list@python.org> (permalink) |
| Lines | 52 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1431283552 news.xs4all.nl 2951 [2001:888:2000:d::a6]:57313 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:90303 |
Show key headers only | View raw
-----------------------------
On Sun, May 10, 2015 5:53 PM CEST Somelauw . wrote:
>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)
>>>
Hi,
I only have Python 2 on my phone, but I am suprised that you (and are able to) decode unicode strings. What result do you get when you do the following in Python 3:
Python 2.7.2 (default, Oct 25 2014, 20:52:15)
[GCC 4.9 20140827 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import codecs
>>> codecs.decode(b'€', 'unicode-escape')
u'\xe2\x82\xac'
>>> codecs.encode(u'€', 'unicode-escape')
'\\xe2\\x82\\xac'
>>>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Why does unicode-escape decode escape symbols that are already escaped? Albert-Jan Roskam <fomcl@yahoo.com> - 2015-05-10 11:39 -0700
csiph-web