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


Groups > comp.lang.python > #62492

Re: bytearray inconsistencies?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'report.': 0.07; '128': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'valueerror:': 0.09; 'bug': 0.12; 'bytearray': 0.16; 'bytearrays,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'separator.': 0.16; 'zero,': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'split': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'skip:( 20': 0.30; '"",': 0.31; 'implicit': 0.31; 'subject:skip:i 10': 0.31; 'file': 0.32; 'up.': 0.33; '(most': 0.33; 'sense': 0.34; "i'd": 0.34; 'but': 0.35; 'there': 0.35; 'consistent': 0.36; 'subject:?': 0.36; 'half': 0.37; 'two': 0.37; 'to:addr:python- list': 0.38; 'recent': 0.39; 'expect': 0.39; 'explain': 0.39; 'skip:b 40': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'simple': 0.61; 'effectively': 0.66; 'cut': 0.74; 'batchelder': 0.84; 'promptly': 0.84; 'cast': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: bytearray inconsistencies?
Date Sat, 21 Dec 2013 14:20:46 +0100
Organization None
References <l92phr$3b2$1@ger.gmane.org> <l92sju$ugd$1@ger.gmane.org> <l941il$9v9$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084b740.dip0.t-ipconnect.de
User-Agent KNode/4.7.3
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.4470.1387632057.18130.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387632057 news.xs4all.nl 2932 [2001:888:2000:d::a6]:43412
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62492

Show key headers only | View raw


Mark Lawrence wrote:

> On 21/12/2013 01:58, Ned Batchelder wrote:
>>
>> If you have a zero, you can split on it with:
>> bytestring.split(bytes([0])), but that doesn't explain why find can take
>> a simple zero, and split has to take a bytestring with a zero in it.
>>
> 
> Create a bytearray(range(256)) and partition it on 128.  I'd expect to
> see the original effectively cut in half with 128 as the separator.  You
> actually get the original with two empty bytearrays, which makes no
> sense to me at all.

>>> bytearray(b"alpha\x00\x00\x00beta").partition(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: empty separator
>>> bytearray(b"alpha\x00\x00\x00beta").partition(1)
(bytearray(b'alpha'), bytearray(b'\x00'), bytearray(b'\x00\x00beta'))
>>> bytearray(b"alpha\x00\x00\x00beta").partition(2)
(bytearray(b'alpha'), bytearray(b'\x00\x00'), bytearray(b'\x00beta'))

suggests that there is an implicit cast to bytearray

>>> bytearray(0)
bytearray(b'')
>>> bytearray(2)
bytearray(b'\x00\x00')

While consistent I don't see how this can ever be the desired behaviour and 
recommend that you file a bug report.
 
> I also looked in test_bytes.py, read as far as "XXX This is a mess" and
> promptly gave up.
 

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


Thread

Re: bytearray inconsistencies? Peter Otten <__peter__@web.de> - 2013-12-21 14:20 +0100

csiph-web