Bytes indexing returns an int

David Robinow drobinow at gmail.com
Tue Jan 7 10:19:13 EST 2014


"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 at 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



More information about the Python-list mailing list