is python 3 better than python 2?

Dan Stromberg drsalists at gmail.com
Wed Apr 6 22:14:46 CEST 2011


On Wed, Apr 6, 2011 at 9:31 AM, MRAB <python at mrabarnett.plus.com> wrote:
> On 06/04/2011 07:06, Dan Stromberg wrote:
>>
>> On Tue, Apr 5, 2011 at 10:04 PM, Terry Reedy <tjreedy at udel.edu
>> <mailto:tjreedy at udel.edu>> wrote:
>>
>>    On 4/5/2011 4:42 PM, John Nagle wrote:
>>
>>        Well, actually Unicode support went in back around Python 2.4.
>>
>>
>>    Even earlier, I think, but there were and still are problems with
>>    unicode in 2.x. Some were and will only be fixed in 3.x.
>>
>>
>>        In 3.x, ASCII strings went away, but that was more of a removal.
>>
>>
>>    Yes and no. They were kept slightly modified as bytes, with all of
>>    the string methods kept.
>>
>>
>> I suspect not all string methods were kept for the bytes type:
>> $ /usr/local/cpython-3.2/bin/python
>> cmd started 2011 Tue Apr 05 11:05:08 PM
>> Python 3.2 (r32:88445, Feb 20 2011, 16:47:11)
>> [GCC 4.4.5] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>  >>> 'a/b/c'.split('/')
>> ['a', 'b', 'c']
>>  >>> b'a/b/c'.split('/')
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> TypeError: Type str doesn't support the buffer API
>>  >>>
>>
> 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']
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Doh.  Thanks.  Now I can eliminate my my_split function.  ^_^



More information about the Python-list mailing list