Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"this': 0.03; 'sys': 0.07; 'string': 0.09; 'appropriate.': 0.09; 'subject:into': 0.09; 'subject:string': 0.09; 'subject:How': 0.10; 'python': 0.11; 'kurt': 0.12; '105,': 0.16; '32,': 0.16; '8-bit': 0.16; 'array.': 0.16; 'expects': 0.16; 'lcd': 0.16; 'macos': 0.16; 'ord': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'command': 0.22; '>>>': 0.22; 'import': 0.22; 'integer': 0.24; 'unicode': 0.24; 'looks': 0.24; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'characters': 0.30; 'subject:list': 0.30; "i'm": 0.30; '>>>>': 0.31; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'set.': 0.36; 'subject:?': 0.36; 'wrong': 0.37; 'two': 0.37; 'message-id:@gmail.com': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'most': 0.60; 'received:62': 0.63; 'header:Message-Id:1': 0.63; 'email addr:gmail.com': 0.63; 'charset:windows-1252': 0.65; 'behavior': 0.77; 'otten': 0.84; 'careful': 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=JdG0usyyimD2FcrM+WIgrDVvYEY4tjg/3k77jFyMapw=; b=GW4Qs/uMdRTOvNRVUfc03a4TxBXkXBrD3RtSMV0v4z1k6Sz/c05crXs3I1cH+kIPZb KnH9U57oH2xG6/NK7EAMAxU9NYUuO/W9HjFnkhyJbKXTyP4VL2sHUPThse/u+ymdIUHq dL0BNPj5BsQNjsC1eRvAoi4yQL+0Um/m81XwFFed7vGj3F3wDM32ZPVutxFD8COvbWWw xVBg8HKoYc8cYlruGw0TbGHk+8Mkhe9jopilghIPHejOZQ/0mz1CwaV/lqopUfgmdDjv qGqMoMGNFSwKk3A+PuFtYK3Xemgm2k5Sa2QSfPW4Y7KdbZ1MR1CsyXuMX+5I8tQDmjCa qNnA== X-Received: by 10.180.102.130 with SMTP id fo2mr5496506wib.29.1409939779288; Fri, 05 Sep 2014 10:56:19 -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 In-Reply-To: <1k9odb-1qs.ln1@chris.zbmc.eu> Date: Fri, 5 Sep 2014 19:56:16 +0200 Content-Transfer-Encoding: quoted-printable References: <1amjdb-p3n.ln1@chris.zbmc.eu> <1k9odb-1qs.ln1@chris.zbmc.eu> 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409939785 news.xs4all.nl 2921 [2001:888:2000:d::a6]:41438 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77603 Am 05.09.2014 um 10:42 schrieb cl@isbd.net: > Joshua Landau wrote: >> On 3 September 2014 15:48, wrote: >>> Peter Otten <__peter__@web.de> wrote: >>>>>>> [ord(c) for c in "This is a string"] >>>> [84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, = 110, 103] >>>>=20 >>>> There are other ways, but you have to describe the use case and = your Python >>>> version for us to recommend the most appropriate. >>>>=20 >>> That looks OK to me. It's just for outputting a string to the block >>> write command in python-smbus which expects an integer array. >>=20 >> Just be careful about Unicode characters. >=20 > I have to avoid them completely because I'm sending the string to a > character LCD with a limited 8-bit only character set. 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=C4'] [65, 195, 132] >>> [ord(c) for c in u'A=C4'] [65, 196] My obviously wrong understanding: =82A=C4=91 in =82ascii=91 are two characters one with ord A=3D65 and one with ord =C4=3D196 ISO8859-1 =97-> why [65, 195, 132] u=92A=C4=92 is an Unicode string =97-> why [65, 196] It is just the other way round as I would expect. Thank you --=20 Kurt Mueller, kurt.alfred.mueller@gmail.com