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


Groups > comp.lang.python > #81088

Re: python 2.7 and unicode (one more time)

Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '21,': 0.07; 'encoded': 0.07; 'string': 0.09; 'bytes,': 0.09; 'encode': 0.09; 'happen.': 0.09; 'subject:2.7': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'bytes;': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'json,': 0.16; 'subject:unicode': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'later': 0.20; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'bytes': 0.24; 'string,': 0.24; 'text.': 0.24; 'unicode': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'quickly': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'asked': 0.31; 'pickle': 0.31; 'quite': 0.32; 'text': 0.33; 'says': 0.33; 'fri,': 0.33; 'subject:time': 0.33; 'could': 0.34; 'subject: (': 0.35; 'skip:u 20': 0.35; 'something': 0.35; 'no,': 0.35; 'operations': 0.35; 'received:google.com': 0.35; 'subject:one': 0.36; "i'll": 0.36; 'being': 0.38; 'nov': 0.38; 'does': 0.39; 'structure': 0.39; 'called': 0.40; 'even': 0.60; "you're": 0.61; "you'll": 0.62; 'subject:more': 0.64; 'more': 0.64; 'hang': 0.67; 'feeling': 0.68; 'music,': 0.84; 'otten': 0.84; 'serious.': 0.84; 'to:none': 0.92; 'sheet': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=o3XGnXzQwq+5Ta2bA4oVOoaOyBnFvzdWW58Y7eK5rl4=; b=xhB+liWwdqULvJh+rs2FqKU6TwZAT4IhHtoAeOIUpZuvFv2z5EMSrGFPDzXeimJHkZ TBUJ6PW+VLg/bAwEfSiBm7aV0hbhw2iBf85Htt77ipRA7TqkmmhzFb/TGOUBEd8LyGn4 ZifE5VTsaDNu0zQkpzrALXft0lAIYcuXSIiEQ5U2vn7EUldZ2mJMOqxfggaApiCFNCFi ZlHDy69fKMFJ8tmOAf+LcD3ZPD0dO3+TkMXk28NUk6eQigdGoUxTApHdUfALSTJ67PVJ 4f/MADOF4dChJhMD/iyTqgXRQMOUqDLEvPNmrlhX4k+fWobXxaanrPG879+kLifgV1ya cXaA==
MIME-Version 1.0
X-Received by 10.42.110.195 with SMTP id r3mr8778261icp.12.1416501984427; Thu, 20 Nov 2014 08:46:24 -0800 (PST)
In-Reply-To <m4l53q$ff4$1@ger.gmane.org>
References <m4kcu8$ta8$1@ger.gmane.org> <m4kn66$ma3$1@ger.gmane.org> <1416491999.209592.193345213.3A6FF9A4@webmail.messagingengine.com> <m4l20h$toc$1@ger.gmane.org> <CAPTjJmqjUGmTA-0JXrkeKYLeShmT=mOE=c38o8YD7XheCK_5Kw@mail.gmail.com> <m4l53q$ff4$1@ger.gmane.org>
Date Fri, 21 Nov 2014 03:46:24 +1100
Subject Re: python 2.7 and unicode (one more time)
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.16028.1416501987.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416501987 news.xs4all.nl 2870 [2001:888:2000:d::a6]:41674
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:81088

Show key headers only | View raw


On Fri, Nov 21, 2014 at 3:32 AM, Peter Otten <__peter__@web.de> wrote:
> Chris Angelico wrote:
>
>> On Fri, Nov 21, 2014 at 2:40 AM, Peter Otten <__peter__@web.de> wrote:
>>> I think that you may get a Unicode/Encode/Error when you try to /decode/
>>> a unicode string is more confusing...
>>
>> Hang on a minute, what does it even mean to decode a Unicode string?
>
> Let's not get philosophical ;)

No, I'm quite serious. You encode Unicode text into bytes; you decode
bytes into text. You can also encode a floating-point value into
bytes, and decode bytes into a float. Or you could encode a large and
complex structure into bytes, using something like pickle or json, and
then decode those bytes later on. The pattern is always the same: the
abstract object with meaning to a human is encoded into a concrete
form that a computer can handle, and the concrete is decoded into the
abstract. If you're not good at sight-reading sheet music, you'll have
the same feeling of staring at the dots, decoding them one by one into
this abstract thing called "music", and then being able to work with
it.

When you try to decode a Unicode string, what happens is that Python 2
says "Oh, you're trying to do a byte-string operation on a Unicode
string... I'll quickly encode that to bytes for you, then do what you
asked". That's why you can get an *en*coding error when you asked to
*de*code - because both operations have to happen.

ChrisA

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


Thread

Re: python 2.7 and unicode (one more time) Chris Angelico <rosuav@gmail.com> - 2014-11-21 03:46 +1100

csiph-web