Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2712
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: is python 3 better than python 2? |
| Date | 2011-04-06 13:01 -0400 |
| References | (1 earlier) <inf9vi$nvm$1@dont-email.me> <4d9b7eaa$0$10570$742ec2ed@news.sonic.net> <ings9q$qse$2@dough.gmane.org> <BANLkTi=waQzxrCfVhsnjB-Q5jnW7EJtpPA@mail.gmail.com> <4D9C954C.4080401@mrabarnett.plus.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.80.1302109317.9059.python-list@python.org> (permalink) |
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 “strings of bytes”, have
all methods found on strings, with the exception of encode(), format()
and isidentifier(), which do not make sense with these types. " If you
find that in error, please file a bug report. You can check with
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 "<stdin>", line 1, in <module>
>> 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
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
bytes and (unicode) strings.
'a/b/c'.split(b'/')
# TypeError: Can't convert 'bytes' object to str implicitly
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
is python 3 better than python 2? neil <neilharper300890@gmail.com> - 2011-04-05 13:42 +0100
Re: is python 3 better than python 2? Mel <mwilson@the-wire.com> - 2011-04-05 14:46 +0000
Re: is python 3 better than python 2? John Nagle <nagle@animats.com> - 2011-04-05 13:42 -0700
Re: is python 3 better than python 2? Terry Reedy <tjreedy@udel.edu> - 2011-04-06 01:04 -0400
Re: is python 3 better than python 2? MRAB <python@mrabarnett.plus.com> - 2011-04-06 17:31 +0100
Re: is python 3 better than python 2? Terry Reedy <tjreedy@udel.edu> - 2011-04-06 13:01 -0400
Re: is python 3 better than python 2? Dan Stromberg <drsalists@gmail.com> - 2011-04-06 13:14 -0700
Re: is python 3 better than python 2? Gnarlodious <gnarlodious@gmail.com> - 2011-04-05 09:50 -0700
csiph-web