Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81097
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: python 2.7 and unicode (one more time) |
| Date | 2014-11-20 18:40 +0100 |
| Organization | None |
| References | (2 earlier) <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> <CAPTjJmoTsZfu2LvUX530_nS9huH0fX7+8NJD4ANNi1kkh1bcew@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16034.1416505270.18130.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: python 2.7 and unicode (one more time) Peter Otten <__peter__@web.de> - 2014-11-20 18:40 +0100
csiph-web