Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '21,': 0.07; 'encoded': 0.07; 'string': 0.09; 'bytes,': 0.09; 'encode': 0.09; 'happen.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:2.7': 0.09; 'python': 0.11; 'changes': 0.15; 'bytes;': 0.16; 'formatted': 0.16; 'json,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:unicode': 0.16; 'underlying': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'later': 0.20; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'bytes': 0.24; 'evolving': 0.24; 'string,': 0.24; 'text,': 0.24; 'text.': 0.24; 'unicode': 0.24; 'looks': 0.24; 'header:X-Complaints-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'quickly': 0.29; 'nature': 0.30; "i'm": 0.30; 'asked': 0.31; 'code': 0.31; '>>>>': 0.31; 'pickle': 0.31; 'interface': 0.32; 'quite': 0.32; 'text': 0.33; 'says': 0.33; 'fri,': 0.33; 'implemented': 0.33; 'subject:time': 0.33; 'could': 0.34; 'problem': 0.35; 'subject: (': 0.35; 'skip:u 20': 0.35; 'something': 0.35; 'no,': 0.35; 'operations': 0.35; 'subject:one': 0.36; "i'll": 0.36; 'being': 0.38; 'nov': 0.38; 'to:addr:python- list': 0.38; 'rather': 0.38; 'does': 0.39; 'structure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'even': 0.60; 'skip:u 10': 0.60; "you're": 0.61; "you'll": 0.62; 'kind': 0.63; 'subject:more': 0.64; 'more': 0.64; 'hang': 0.67; 'feeling': 0.68; 'music,': 0.84; 'otten': 0.84; 'serious.': 0.84; 'universe': 0.84; 'cast': 0.91; 'sheet': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: python 2.7 and unicode (one more time) Date: Thu, 20 Nov 2014 18:40:52 +0100 Organization: None References: <1416491999.209592.193345213.3A6FF9A4@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bdb1b4.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416505270 news.xs4all.nl 2898 [2001:888:2000:d::a6]:41296 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81097 Chris Angelico wrote: > 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. I'm sorry I'm limited to text, otherwise I would have formatted the ";)" as 30pt blinking magenta... > 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. In an alternative universe unicode.decode() could have been implemented as a no-op. As you put it it looks like you have to find the true nature of the problem and then cast it into code -- a kind of essentialism. I would rather emphasise the process; the evolving interface changes your view on the underlying problem -- a hermeneutic cycle if you will.