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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 "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 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