Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; '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; 'language.': 0.14; 'bytearray': 0.16; 'bytearrays,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'separator.': 0.16; 'zero,': 0.16; 'all.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'split': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'url:bugs': 0.29; "doesn't": 0.30; 'skip:( 20': 0.30; '"",': 0.31; '>>>>': 0.31; 'implicit': 0.31; 'subject:skip:i 10': 0.31; 'file': 0.32; 'url:python': 0.33; '(most': 0.33; 'sense': 0.34; "i'd": 0.34; 'but': 0.35; 'there': 0.35; 'consistent': 0.36; 'subject:?': 0.36; 'url:org': 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; 'simple': 0.61; 'our': 0.64; 'effectively': 0.66; 'cut': 0.74; 'batchelder': 0.84; 'otten': 0.84; 'received:89': 0.85; 'cast': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: bytearray inconsistencies? Date: Sat, 21 Dec 2013 19:53:41 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-89-240-169-246.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387655647 news.xs4all.nl 2862 [2001:888:2000:d::a6]:39456 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62510 On 21/12/2013 13:20, Peter Otten wrote: > 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 "", line 1, in > 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. > http://bugs.python.org/issue20047 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence