Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; '*not*': 0.05; 'report.': 0.05; 'names.': 0.07; 'terry': 0.07; '3.x': 0.09; 'attribute': 0.09; 'bytearray': 0.09; 'implicitly': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'str': 0.09; 'looked': 0.10; 'api': 0.11; 'pm,': 0.11; 'this:': 0.11; '>>>': 0.12; 'exception': 0.12; 'wrote:': 0.14; 'subject:python': 0.15; 'called,': 0.16; 'coercions': 0.16; 'mrab': 0.16; 'reedy': 0.16; 'type:': 0.16; 'traceback': 0.16; '(most': 0.16; 'possibly': 0.16; 'bytes': 0.19; 'jan': 0.22; 'header:In-Reply-To:1': 0.22; 'convert': 0.22; 'trying': 0.23; 'doc': 0.23; 'last):': 0.23; 'objects,': 0.23; 'once.': 0.23; 'suspect': 0.25; 'says': 0.25; 'object': 0.27; 'skip:b 20': 0.27; "doesn't": 0.28; 'string': 0.29; 'error': 0.29; 'subject:?': 0.29; 'strings,': 0.31; 'strings.': 0.31; 'typeerror:': 0.31; 'types.': 0.31; "can't": 0.31; 'random': 0.31; "skip:' 10": 0.32; 'to:addr:python-list': 0.32; 'execution': 0.33; 'using': 0.34; 'header:X-Complaints- To:1': 0.34; 'change': 0.34; 'message.': 0.35; 'file': 0.35; 'header:User-Agent:1': 0.35; '"",': 0.35; 'message,': 0.37; 'but': 0.38; 'received:org': 0.38; 'set': 0.39; 'to:addr:python.org': 0.39; 'header:Mime-Version:1': 0.39; 'header:Received:5': 0.40; 'split': 0.60; 'charset:windows-1252': 0.61; 'believe': 0.66; 'automatic': 0.71; 'kept': 0.73; '(unicode)': 0.84; 'elimination': 0.84; 'subject:better': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: is python 3 better than python 2? Date: Wed, 06 Apr 2011 13:01:42 -0400 References: <4d9b7eaa$0$10570$742ec2ed@news.sonic.net> <4D9C954C.4080401@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: rain.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 In-Reply-To: <4D9C954C.4080401@mrabarnett.plus.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 40 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1302109317 news.xs4all.nl 81481 [::ffff:82.94.164.166]:39922 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:2712 On 4/6/2011 12:31 PM, MRAB wrote: > On 06/04/2011 07:06, Dan Stromberg wrote: >> I suspect not all string methods were kept for the bytes type: Doc says "Bytes and bytearray objects, being =93strings of bytes=94, have= =20 all methods found on strings, with the exception of encode(), format()=20 and isidentifier(), which do not make sense with these types. " If you=20 find that in error, please file a bug report. You can check with=20 dir(str) and dir(bytes), possibly using set differences. But I believe I = did that once. >> >>> 'a/b/c'.split('/') >> ['a', 'b', 'c'] >> >>> b'a/b/c'.split('/') >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: Type str doesn't support the buffer API Known confusing error message, but notice that you did *not* get AttributeError: 'bytes' object has no attribute 'split' which is the error you get for random names. So .split was successfully=20 looked up and then called, and its execution gave the above message. > You're trying to split bytes with a str (Unicode) argument. Try this: > > >>> b'a/b/c'.split(b'/') > [b'a', b'b', b'c'] One change in 3.x is the elimination of automatic coercions between=20 bytes and (unicode) strings. 'a/b/c'.split(b'/') # TypeError: Can't convert 'bytes' object to str implicitly --=20 Terry Jan Reedy