Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.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; 'that?': 0.05; 'subject:Python': 0.06; '(so': 0.07; 'diff': 0.07; "'a'": 0.09; 'arrays': 0.09; 'assumed': 0.09; 'assuming': 0.09; 'encode': 0.09; 'integers': 0.09; 'lookup': 0.09; 'strings.': 0.09; 'translate': 0.10; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'assume': 0.14; 'question.': 0.14; "wouldn't": 0.14; 'clunky': 0.16; 'codec': 0.16; 'dict': 0.16; 'dig': 0.16; 'ebcdic': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integers,': 0.16; 'ordinals': 0.16; 'roy': 0.16; 'subject:More': 0.16; 'subject:Unicode': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'thanks.': 0.20; 'written': 0.21; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'integer': 0.24; 'lets': 0.24; 'typical': 0.24; 'unicode': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'array': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'another.': 0.31; 'easy,': 0.31; 'please.': 0.31; 'subject:About': 0.31; 'values.': 0.31; 'probably': 0.32; 'checked': 0.32; 'extend': 0.32; 'languages': 0.32; 'stuff': 0.32; 'text': 0.33; 'table': 0.34; 'there,': 0.34; 'problem': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'much.': 0.36; "didn't": 0.36; 'method': 0.36; 'expected': 0.38; 'mapping': 0.38; 'pm,': 0.38; 'that,': 0.38; 'little': 0.38; 'use.': 0.39; 'either': 0.39; 'how': 0.40; 'even': 0.60; 'easy': 0.60; 'subject:"': 0.60; 'full': 0.61; "you're": 0.61; 'smith': 0.68; 'presumably': 0.84; 'to:none': 0.92 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:cc :content-type; bh=bwDZNhIG7Z7seh+QvP/W2Zif3+ti+8ZECaJGpMRqek0=; b=SiAeEsgND4OjdEY/I9dNwQR1/bwZEdWAbJR+Wcmvq6y6Eb0VBtJRqwMTz7B/uIAC+P AZ33uPNyFhnEF3c+SbeF9UcfJilyo0/KUYm71zOwe6+X0LqGbmksVjGnyCYLHoVozrc6 J2T1rVHyhPtiwTfJ1iy6mugrk3SOciMEnFVBFlHu46lh7QMH1GHYsDleJt7jC3etnGg/ o5UdJzB0IQhhRXX/grBtgRQmuNCix8uab9asQAf9cOXiFoXUYi4Ublt1wzHGiGZcgI5s AqFdThGvb7HTn9hXK/sVqOCu9PtP+Jqj70sgNttJdm8owFy9lLHZBQwXwNKwEeKsm8vF sfGQ== MIME-Version: 1.0 X-Received: by 10.68.108.194 with SMTP id hm2mr123140580pbb.22.1388984374877; Sun, 05 Jan 2014 20:59:34 -0800 (PST) In-Reply-To: References: <52CA13BD.4050708@stoneleaf.us> Date: Mon, 6 Jan 2014 15:59:34 +1100 Subject: Re: "More About Unicode in Python 2 and 3" From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388984378 news.xs4all.nl 2909 [2001:888:2000:d::a6]:44036 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63270 On Mon, Jan 6, 2014 at 3:49 PM, Roy Smith wrote: > Thanks. But, I see I didn't formulate my problem statement well. I was > (naively) assuming there wouldn't be a built-in codec for rot-13. Let's > assume there isn't; I was trying to find a case where you had to treat > the data as integers in one place and text in another. How would you do > that? I assumed that you would have checked that one, and answered accordingly :) Though I did dig into the EBCDIC part of the question. My thinking is that, if you're working with integers, you probably mean either bytes (so encode it before you do stuff - typical for crypto) or codepoints / Unicode ordinals (so use ord()/chr()). In other languages there are ways to treat strings as though they were arrays of integers (lots of C-derived languages treat 'a' as 97 and "a"[0] as 97 also; some extend this to the full Unicode range), and even there, I almost never actually use that identity much. There's only one case that I can think of where I did a lot of string<->integer-array transmutation, and that was using a diff function that expected an integer array - if the transformation to and from strings hadn't been really easy, that function would probably have been written to take strings. The Py2 str.translate() method was a little clunky to use, but presumably fast to execute - you build up a lookup table and translate through that. The Py3 equivalent takes a dict mapping the from and to values. Pretty easy to use. And it lets you work with codepoints or strings, as you please. ChrisA