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


Groups > comp.lang.python > #63430

Re: Bytes indexing returns an int

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!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <drobinow@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'one?': 0.05; 'indexing': 0.07; 'python3': 0.07; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'considers': 0.16; 'ordinal': 0.16; 'prefer.': 0.16; 'rationale': 0.16; 'slice.': 0.16; 'substring': 0.16; 'surprising': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'bytes': 0.24; "haven't": 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; "d'aprano": 0.31; 'extract': 0.31; 'steven': 0.31; 'anyone': 0.31; 'allows': 0.31; 'url:python': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'behind': 0.37; 'rather': 0.38; 'does': 0.39; 'url:mail': 0.40; 'easy': 0.60; 'length': 0.61; 'making': 0.63; 'behavior': 0.77; '(is': 0.84; 'embraced': 0.84; 'received :mail-ob0-x22f.google.com': 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=W4mtGi/oEdXF8jOBvIZ8vgT5znd+VF4ZDOiv3aZlRGQ=; b=dH9qemKt22GYOX68HdWc4MhRe2vg6nXywPlUcKbHZxDM4U2TqgfLIaKdHfjKqB4asK FYVqTedy7/WMPseTgUleCncc80mROnO4ahuyosrpFkGCMK7hW2t53zb/an9kqw1njb4D MNuWTnyWvmhgOp4nIpGCfyzJ2XcLiv/WOq5Gc1vfpEHOOFRl6KCXxbPnITEROaNlnaRL iVBVP46K9YvA2XUbIVfMZ5aJpPEQ0qJNtP4WCdlqMIkJDv0mrE2jVMXTO842pLAsSbQl 5Ap52C+mzQDDV8W3+kvMgX90sMasSI5i7GL8UNwzYicYzVUgkA85qgPFDNjPjp+7fh0a hh3w==
MIME-Version 1.0
X-Received by 10.60.98.101 with SMTP id eh5mr1826117oeb.53.1389107953424; Tue, 07 Jan 2014 07:19:13 -0800 (PST)
In-Reply-To <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com>
References <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com>
Date Tue, 7 Jan 2014 10:19:13 -0500
Subject Re: Bytes indexing returns an int
From David Robinow <drobinow@gmail.com>
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 <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.5135.1389107956.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389107956 news.xs4all.nl 2885 [2001:888:2000:d::a6]:50992
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63430

Show key headers only | View raw


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