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


Groups > comp.lang.python > #62492 > unrolled thread

Re: bytearray inconsistencies?

Started byPeter Otten <__peter__@web.de>
First post2013-12-21 14:20 +0100
Last post2013-12-21 14:20 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#62492 — Re: bytearray inconsistencies?

FromPeter Otten <__peter__@web.de>
Date2013-12-21 14:20 +0100
SubjectRe: bytearray inconsistencies?
Message-ID<mailman.4470.1387632057.18130.python-list@python.org>
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.
 

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web