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


Groups > comp.lang.python > #90313

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

References <1431283174.10170.BPMail_high_carrier@web163801.mail.gq1.yahoo.com>
Date 2015-05-11 01:45 +0200
Subject Re: Why does unicode-escape decode escape symbols that are already escaped?
From "Somelauw ." <somelauw@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.327.1431301543.12865.python-list@python.org> (permalink)

Show all headers | View raw


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

2015-05-10 20:39 GMT+02:00 Albert-Jan Roskam <fomcl@yahoo.com>:

>
> 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'
> >>>
>
>
Python 3.3.3 (default, Nov 27 2013, 17:12:35)
[GCC 4.8.2] on linux
>>> import codecs
>>> codecs.decode(b'€', 'unicode-escape')
  File "<stdin>", line 1
SyntaxError: bytes can only contain ASCII literal characters.
>>> codecs.encode(u'€', 'unicode-escape')
b'\\u20ac'

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


Thread

Re: Why does unicode-escape decode escape symbols that are already escaped? "Somelauw ." <somelauw@gmail.com> - 2015-05-11 01:45 +0200

csiph-web