Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63430
| References | <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2014-01-07 10:19 -0500 |
| Subject | Re: Bytes indexing returns an int |
| From | David Robinow <drobinow@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5135.1389107956.18130.python-list@python.org> (permalink) |
"treating bytes as chars" considered harmful? I don't know the answer to your question but the behavior seems right to me. Python 3 grudgingly allows the "abomination" of byte strings (is that what they're called? I haven't fully embraced Python3 yet). If you want a substring you use a slice. b = b'xyz' b[1:2] => b'y' also, chr(121) => 'y' which is really what the Python 3 gods prefer. On Tue, Jan 7, 2014 at 6:13 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > Does anyone know what the rationale behind making byte-string indexing > return an int rather than a byte-string of length one? > > That is, given b = b'xyz', b[1] returns 121 rather than b'y'. > > This is especially surprising when one considers that it's easy to extract > the ordinal value of a byte: > > ord(b'y') => 121 > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Bytes indexing returns an int Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-07 22:13 +1100
Re: Bytes indexing returns an int Ervin Hegedüs <airween@gmail.com> - 2014-01-07 12:53 +0100
Re: Bytes indexing returns an int Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-07 23:04 +1100
Re: Bytes indexing returns an int Terry Reedy <tjreedy@udel.edu> - 2014-01-07 09:29 -0500
Re: Bytes indexing returns an int David Robinow <drobinow@gmail.com> - 2014-01-07 10:19 -0500
Re: Bytes indexing returns an int Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-08 03:12 +1100
Re: Bytes indexing returns an int Serhiy Storchaka <storchaka@gmail.com> - 2014-01-07 21:48 +0200
Re: Bytes indexing returns an int Robin Becker <robin@reportlab.com> - 2014-01-08 11:05 +0000
Re: Bytes indexing returns an int wxjmfauth@gmail.com - 2014-01-08 08:08 -0800
Re: Bytes indexing returns an int Ned Batchelder <ned@nedbatchelder.com> - 2014-01-08 12:19 -0500
Re: Bytes indexing returns an int Piet van Oostrum <piet@vanoostrum.org> - 2014-01-09 18:05 +0100
Re: Bytes indexing returns an int Ethan Furman <ethan@stoneleaf.us> - 2014-01-09 09:28 -0800
Re: Bytes indexing returns an int Serhiy Storchaka <storchaka@gmail.com> - 2014-01-09 21:36 +0200
Re: Bytes indexing returns an int Michael Torrie <torriem@gmail.com> - 2014-01-08 10:25 -0700
Re: Bytes indexing returns an int David Robinow <drobinow@gmail.com> - 2014-01-07 10:23 -0500
Re: Bytes indexing returns an int Ethan Furman <ethan@stoneleaf.us> - 2014-01-07 09:02 -0800
Re: Bytes indexing returns an int Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-08 11:15 +1100
Re: Bytes indexing returns an int Chris Angelico <rosuav@gmail.com> - 2014-01-08 11:30 +1100
Re: Bytes indexing returns an int Grant Edwards <invalid@invalid.invalid> - 2014-01-08 02:34 +0000
Re: Bytes indexing returns an int Chris Angelico <rosuav@gmail.com> - 2014-01-08 14:46 +1100
Re: Bytes indexing returns an int Ethan Furman <ethan@stoneleaf.us> - 2014-01-07 16:37 -0800
csiph-web