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


Groups > comp.lang.python > #77610

Re: How to turn a string into a list of integers?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <kurt.alfred.mueller@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'matches': 0.07; 'sys': 0.07; 'utf-8': 0.07; 'string': 0.09; '128': 0.09; 'ascii': 0.09; 'bytes,': 0.09; 'bytes.': 0.09; 'converted': 0.09; 'subject:into': 0.09; 'subject:string': 0.09; 'subject:How': 0.10; 'python': 0.11; 'kurt': 0.12; 'ack': 0.16; 'btw:': 0.16; 'encodings': 0.16; 'macos': 0.16; 'ord': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'starts': 0.20; '>>>': 0.22; 'import': 0.22; 'byte': 0.24; 'logical': 0.24; 'unicode': 0.24; 'second': 0.26; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; 'characters': 0.30; 'subject:list': 0.30; 'bunch': 0.31; 'decimal': 0.31; 'omitted': 0.31; 'sep': 0.31; 'third': 0.33; 'could': 0.34; 'received:google.com': 0.35; 'subject:?': 0.36; 'wrong': 0.37; 'two': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'kindly': 0.61; 'first': 0.61; 'received:62': 0.63; 'header:Message-Id:1': 0.63; 'email addr:gmail.com': 0.63; 'real': 0.63; 'charset:windows-1252': 0.65; 'covers': 0.68; 'behavior': 0.77; 'yielded': 0.84; 'aka': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=vTGNXvJb6eqiB5lH0Vt4T3XbsoFsfM9HUDl20VF7OuE=; b=sKQRBGwJSLyr9Brn4nVntmoFSh7ge1ASY0OcEyETSHlEUToXQOFp0yUZUp9ySWg1mg BCPS9uin6XES6dTCQ7dI8S3utgJERRHIF2he46+mAK8YN1YKm/UbdPWtgDaB8HYFhL+F GNob/nEoYa1Ps89hgpYxtSy1fLXPmPIMK3ZX+GXea5xDLjHVB3gKw72VaPL+6INn2bDF u92ztRY4on/fyihqZQH1sZIz5xvWEmRLljdI0knIpkiI17xwH/HL0BpDSHzSKKcunNAN Qj/tMmLUBmoOvvC8m/OY4AqALar26Lf/ExGJgsLR5uxTYbYwfFH6WZGJ8x5tsxk22Hi1 YzAw==
X-Received by 10.194.84.175 with SMTP id a15mr14901832wjz.12.1409944616235; Fri, 05 Sep 2014 12:16:56 -0700 (PDT)
Content-Type text/plain; charset=windows-1252
Mime-Version 1.0 (Mac OS X Mail 7.3 \(1878.6\))
Subject Re: How to turn a string into a list of integers?
From Kurt Mueller <kurt.alfred.mueller@gmail.com>
In-Reply-To <CAMw+j7LZu2YWw1UkAYvBnX7LZDJncP5Euh5aYjxYVvWnH=CgwA@mail.gmail.com>
Date Fri, 5 Sep 2014 21:16:54 +0200
Content-Transfer-Encoding quoted-printable
References <h2ejdb-mdk.ln1@chris.zbmc.eu> <mailman.13738.1409748804.18130.python-list@python.org> <1amjdb-p3n.ln1@chris.zbmc.eu> <mailman.13776.1409864831.18130.python-list@python.org> <1k9odb-1qs.ln1@chris.zbmc.eu> <E915BA7F-DAFA-4D9A-B70B-0C6EECD68484@gmail.com> <CAMw+j7LZu2YWw1UkAYvBnX7LZDJncP5Euh5aYjxYVvWnH=CgwA@mail.gmail.com>
To python-list@python.org
X-Mailer Apple Mail (2.1878.6)
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.13806.1409944624.18130.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1409944624 news.xs4all.nl 2952 [2001:888:2000:d::a6]:37702
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77610

Show key headers only | View raw


Am 05.09.2014 um 20:25 schrieb Chris “Kwpolska” Warrick <kwpolska@gmail.com>:
> On Sep 5, 2014 7:57 PM, "Kurt Mueller" <kurt.alfred.mueller@gmail.com> wrote:
> > Could someone please explain the following behavior to me:
> > Python 2.7.7, MacOS 10.9 Mavericks
> >
> > >>> import sys
> > >>> sys.getdefaultencoding()
> > 'ascii'
> > >>> [ord(c) for c in 'AÄ']
> > [65, 195, 132]
> > >>> [ord(c) for c in u'AÄ']
> > [65, 196]
> >
> > My obviously wrong understanding:
> > ‚AÄ‘ in ‚ascii‘ are two characters
> >      one with ord A=65 and
> >      one with ord Ä=196 ISO8859-1 <depends on code table>
> >      —-> why [65, 195, 132]
> > u’AÄ’ is an Unicode string
> >      —-> why [65, 196]
> >
> > It is just the other way round as I would expect.
> 
> Basically, the first string is just a bunch of bytes, as provided by your terminal — which sounds like UTF-8 (perfectly logical in 2014).  The second one is converted into a real Unicode representation. The codepoint for Ä is U+00C4 (196 decimal). It's just a coincidence that it also matches latin1 aka ISO 8859-1 as Unicode starts with all 256 latin1 codepoints. Please kindly forget encodings other than UTF-8.

So:
‘AÄ’ is an UTF-8 string represented by 3 bytes:
A -> 41   -> 65  first byte decimal
Ä -> c384 -> 195 and 132 second and third byte decimal

u’AÄ’ is an Unicode string represented by 2 bytes?:
A -> U+0041 -> 65 first byte decimal, 00 is omitted or not yielded by ord()?
Ä -> U+00C4 -> 196 second byte decimal, 00 is ommited or not yielded by ord()?


> BTW: ASCII covers only the first 128 bytes.

ACK
-- 
Kurt Mueller, kurt.alfred.mueller@gmail.com

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


Thread

How to turn a string into a list of integers? cl@isbd.net - 2014-09-03 13:27 +0100
  Re: How to turn a string into a list of integers? Peter Otten <__peter__@web.de> - 2014-09-03 14:52 +0200
    Re: How to turn a string into a list of integers? cl@isbd.net - 2014-09-03 15:48 +0100
      Re: How to turn a string into a list of integers? Joshua Landau <joshua@landau.ws> - 2014-09-04 22:06 +0100
        Re: How to turn a string into a list of integers? cl@isbd.net - 2014-09-05 09:42 +0100
          Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-05 19:56 +0200
            Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-06 15:47 +1000
              Re: How to turn a string into a list of integers? Peter Otten <__peter__@web.de> - 2014-09-06 10:22 +0200
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-06 21:17 +1000
              Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-06 14:15 +0200
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-07 04:19 +1000
                Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-06 21:28 +0200
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-07 11:47 +1000
                Re: How to turn a string into a list of integers? MRAB <python@mrabarnett.plus.com> - 2014-09-07 15:52 +0100
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-08 03:02 +1000
                Re: How to turn a string into a list of integers? Rustom Mody <rustompmody@gmail.com> - 2014-09-07 10:53 -0700
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-08 04:08 +1000
                Re: How to turn a string into a list of integers? Rustom Mody <rustompmody@gmail.com> - 2014-09-07 11:34 -0700
                Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-08 10:14 +1000
                Re: How to turn a string into a list of integers? Marko Rauhamaa <marko@pacujo.net> - 2014-09-08 08:44 +0300
                Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-08 15:53 +1000
                Re: How to turn a string into a list of integers? Terry Reedy <tjreedy@udel.edu> - 2014-09-08 03:41 -0400
                Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-08 01:04 +1000
                Re: How to turn a string into a list of integers? Roy Smith <roy@panix.com> - 2014-09-07 11:40 -0400
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-08 04:00 +1000
                Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-08 10:12 +1000
              Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-06 22:23 +1000
          Re: How to turn a string into a list of integers? Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2014-09-05 20:25 +0200
          Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-05 21:16 +0200
          Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-05 22:41 +0200
      Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-05 10:12 +1000
      Re: How to turn a string into a list of integers? Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-04 20:09 -0600
      Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-05 12:15 +1000
        Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-06 14:27 +1000
  Re: How to turn a string into a list of integers? obedrios@gmail.com - 2014-09-03 07:30 -0700

csiph-web