Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.kamp.net!newsfeed.kamp.net!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed3a.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.000 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; '\xe2\x80\x94': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'btw:': 0.16; 'encodings': 0.16; 'galaxy': 0.16; 'macos': 0.16; 'ord': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'starts': 0.20; '>>>': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; '>>>': 0.24; 'logical': 0.24; 'unicode': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'characters': 0.30; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'bunch': 0.31; 'sep': 0.31; 'could': 0.34; 'received:google.com': 0.35; 'subject:?': 0.36; 'wrong': 0.37; 'two': 0.37; 'pm,': 0.38; 'explain': 0.39; 'skip:u 10': 0.60; 'kindly': 0.61; 'from:charset:utf-8': 0.61; 'first': 0.61; 'real': 0.63; 'skip:\xe2 10': 0.65; 'to:addr:gmail.com': 0.65; 'covers': 0.68; '8bit%:43': 0.74; 'behavior': 0.77; 'aka': 0.91 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:to :cc:content-type; bh=W5oj0nfYbDHwIfVLO6PpoOVnnBIiejfV9CT4qHEihWw=; b=l9IB7pPUsrsDxs5huWI8ExiWIdE3wXBY+cTI/XPZ02c2WrLj8Es8AG9v2Cf6WcxGGH Em1POBFQb0bJXv3Bp/zAcjPlHjxBCVqdCgoWnxpZogh8MIxwbUevST3p+VGPRUKuZIN8 f1vW9CHncb02qmN5v9Vto9CjGYRXos2hIWNSb69utugnF0FzfGcrPkdyOh/2NXAhNQOK LeAe1+1jNtHZD7VsqpqDVF6vmysTjelD+/wh7/58NDY0Okv0in2axajvimqNYw3QQT97 FGCrDxt0BoKqSdZk9DhzuDak7BfbP206XMP8veyz/yRa4yrHx5qR8o4t5O/UmBqNSz9P Q1Uw== MIME-Version: 1.0 X-Received: by 10.50.147.38 with SMTP id th6mr7362522igb.31.1409941516307; Fri, 05 Sep 2014 11:25:16 -0700 (PDT) In-Reply-To: References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> Date: Fri, 5 Sep 2014 20:25:16 +0200 Subject: Re: How to turn a string into a list of integers? From: =?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?= To: Kurt Mueller Content-Type: multipart/alternative; boundary=089e013a0a5c3bd2e70502559771 Cc: python-list@python.org 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: 85 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409941524 news.xs4all.nl 2881 [2001:888:2000:d::a6]:52132 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77606 --089e013a0a5c3bd2e70502559771 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sep 5, 2014 7:57 PM, "Kurt Mueller" 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=C3=84'] > [65, 195, 132] > >>> [ord(c) for c in u'A=C3=84'] > [65, 196] > > My obviously wrong understanding: > =E2=80=9AA=C3=84=E2=80=98 in =E2=80=9Aascii=E2=80=98 are two characters > one with ord A=3D65 and > one with ord =C3=84=3D196 ISO8859-1 > =E2=80=94-> why [65, 195, 132] > u=E2=80=99A=C3=84=E2=80=99 is an Unicode string > =E2=80=94-> 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 =E2=80=94 which sounds like UTF-8 (perfectly logical in 2014). Th= e second one is converted into a real Unicode representation. The codepoint for =C3= =84 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. BTW: ASCII covers only the first 128 bytes. -- Chris =E2=80=9CKwpolska=E2=80=9D Warrick Sent from my Galaxy S3. --089e013a0a5c3bd2e70502559771 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

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=C3=84']
> [65, 195, 132]
> >>> [ord(c) for c in u'A=C3=84']
> [65, 196]
>
> My obviously wrong understanding:
> =E2=80=9AA=C3=84=E2=80=98 in =E2=80=9Aascii=E2=80=98 are two character= s
> =C2=A0 =C2=A0 =C2=A0one with ord A=3D65 and
> =C2=A0 =C2=A0 =C2=A0one with ord =C3=84=3D196 ISO8859-1 <depends on= code table>
> =C2=A0 =C2=A0 =C2=A0=E2=80=94-> why [65, 195, 132]
> u=E2=80=99A=C3=84=E2=80=99 is an Unicode string
> =C2=A0 =C2=A0 =C2=A0=E2=80=94-> 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 pro= vided by your terminal =E2=80=94 which sounds like UTF-8 (perfectly logical= in 2014).=C2=A0 The second one is converted into a real Unicode representa= tion. The codepoint for =C3=84 is U+00C4 (196 decimal). It's just a coi= ncidence 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.=

BTW: ASCII covers only the first 128 bytes.

--
Chris =E2=80=9CKwpolska=E2=80=9D Warrick <http://chriswarrick.com/>
Sent from my Galaxy S3.

--089e013a0a5c3bd2e70502559771--