Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63270
| References | (4 earlier) <52CA13BD.4050708@stoneleaf.us> <mailman.5001.1388976943.18130.python-list@python.org> <roy-7ED5DF.23241105012014@news.panix.com> <mailman.5004.1388983234.18130.python-list@python.org> <roy-13C7CE.23494705012014@news.panix.com> |
|---|---|
| Date | 2014-01-06 15:59 +1100 |
| Subject | Re: "More About Unicode in Python 2 and 3" |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5006.1388984378.18130.python-list@python.org> (permalink) |
On Mon, Jan 6, 2014 at 3:49 PM, Roy Smith <roy@panix.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: "More About Unicode in Python 2 and 3" Chris Angelico <rosuav@gmail.com> - 2014-01-06 13:55 +1100
Re: "More About Unicode in Python 2 and 3" Roy Smith <roy@panix.com> - 2014-01-05 23:24 -0500
Re: "More About Unicode in Python 2 and 3" Tim Chase <python.list@tim.thechases.com> - 2014-01-05 22:41 -0600
Re: "More About Unicode in Python 2 and 3" Roy Smith <roy@panix.com> - 2014-01-05 23:49 -0500
Re: "More About Unicode in Python 2 and 3" Chris Angelico <rosuav@gmail.com> - 2014-01-06 15:59 +1100
Re: "More About Unicode in Python 2 and 3" Chris Angelico <rosuav@gmail.com> - 2014-01-06 15:51 +1100
Re: "More About Unicode in Python 2 and 3" Tim Chase <python.list@tim.thechases.com> - 2014-01-06 05:49 -0600
Re: "More About Unicode in Python 2 and 3" Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-07 03:24 +1100
Re: "More About Unicode in Python 2 and 3" Chris Angelico <rosuav@gmail.com> - 2014-01-07 03:30 +1100
Re: "More About Unicode in Python 2 and 3" Serhiy Storchaka <storchaka@gmail.com> - 2014-01-06 22:20 +0200
Re: "More About Unicode in Python 2 and 3" Serhiy Storchaka <storchaka@gmail.com> - 2014-01-06 22:21 +0200
Re: "More About Unicode in Python 2 and 3" Tim Chase <python.list@tim.thechases.com> - 2014-01-06 14:42 -0600
Re: "More About Unicode in Python 2 and 3" Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-06 20:47 +0000
Re: "More About Unicode in Python 2 and 3" Chris Angelico <rosuav@gmail.com> - 2014-01-07 10:06 +1100
csiph-web