Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63456

Re: Bytes indexing returns an int

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'string.': 0.05; 'indexing': 0.07; 'string': 0.09; 'methods,': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'jan': 0.12; '42,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'immutability': 0.16; 'inconvenient': 0.16; 'notation': 0.16; 'quoted': 0.16; 'tuple': 0.16; 'wrote:': 0.18; '(not': 0.18; 'wed,': 0.18; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'convenient': 0.24; 'string,': 0.24; 'decide': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; 'code': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'this.': 0.32; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'useful': 0.36; 'similar': 0.36; 'list': 0.37; 'fact': 0.38; 'rather': 0.38; 'that,': 0.38; 'major': 0.40; 'even': 0.60; 'more': 0.64; 'attractive': 0.81; '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=zFJTKmoXPMsxXWv9TV4FTQXg5Rc3twLbzggzRz6bK1Q=; b=1Gs3dMNADk+NBVgiij70VndoDnAg6HM8jhckVwENPL9gTr9qbr2l6TMQkK9M6mIfOn NiJaYrjZoRjhE76ySZy+DNboH5yBrU4ckBASMjEjXtj8Jh5K4puUWuT7Z3+6rI0rxpPJ 1RDNuXz7pIbygk4i4J3yg8x5RWlZGK4gFZrCKIkmPhpmaufDUKIv+91lSpkgBhc1Sp2V B2e73Kwf0nyNaupqgLqJPeojLosMzj1/NaJKU0ZRirEIKh/L3u/tvSblG+Xv6pNmqP48 BBZOOHWkx2sVTGNEHSDZ8UZwLL0l2+0DcSjuelbQlwBtTxvj5oELpK4VJ4DneZzOQBxX UNdg==
MIME-Version 1.0
X-Received by 10.68.108.194 with SMTP id hm2mr139255791pbb.22.1389141049367; Tue, 07 Jan 2014 16:30:49 -0800 (PST)
In-Reply-To <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com>
References <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <CAF3XjbweCcbNE7Lb+JVXdThPj=jfqUChMEmB6CVOqxjh6TEvcA@mail.gmail.com> <mailman.5146.1389117017.18130.python-list@python.org> <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com>
Date Wed, 8 Jan 2014 11:30:49 +1100
Subject Re: Bytes indexing returns an int
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5155.1389141054.18130.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389141054 news.xs4all.nl 2892 [2001:888:2000:d::a6]:40392
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63456

Show key headers only | View raw


On Wed, Jan 8, 2014 at 11:15 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Why decide that the bytes type is best considered as a list of
> bytes rather than a string of bytes? It doesn't have any list methods, it
> looks like a string and people use it as a string. As you have discovered,
> it is an inconvenient annoyance that indexing returns an int instead of a
> one-byte byte-string.
>
> I think that, in hindsight, this was a major screw-up in Python 3.

Which part was? The fact that it can be represented with a (prefixed)
quoted string?

bytes_value = (41, 42, 43, 44)
string = bytes_value.decode()  # "ABCD"

I think it's more convenient to let people use a notation similar to
what was used in Py2, but perhaps this is an attractive nuisance, if
it gives rise to issues like this. If a bytes were more like a tuple
of ints (not a list - immutability is closer) than it is like a
string, would that be clearer?

Perhaps the solution isn't even a code one, but a mental one. "A bytes
is like a tuple of ints" might be a useful mantra.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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