On Sun, Oct 5, 2008 at 11:43 PM, Steve Holden <[EMAIL PROTECTED]> wrote:
> This does make it look rather as though bytes == str was a decision
> whose consequences weren't fully appreciated before implementation.
>

Well, you could say that about almost any change.

> Was this horror anticipated?

I didn't anticipate it.

>
> regards
>  Steve
>
> -------- Original Message --------
> Subject: In Python 2.6, bytes is str
> Date: Sun, 05 Oct 2008 22:30:17 -0700
> From: Bryan Olson <[EMAIL PROTECTED]>
> Organization: at&t http://my.att.net/
> To: [EMAIL PROTECTED]
> Newsgroups: gmane.comp.python.general
>
>
> Python 3 has the 'bytes' type, which the string type I've long wanted in
> various languages. Among other advantages, it is immutable, and
> therefore bytes objects can be dict keys. There's a mutable version too,
> called "bytearray".
>
> In Python 2.6, the name 'bytes' is defined, and bound to str. The 2.6
> assignment presents some pitfalls. Be aware.
>
> Consider constructing a bytes object as:
>
>    b = bytes([68, 255, 0])
>
> In Python 3.x, len(b) will be 3, which feels right.
>
> In Python 2.6, len(b) will be  12, because b is the str, '[68, 255, 0]'.
>
>
> I'm thinking I should just avoid using 'bytes' in Python 2.6. If there's
>  another Python release between 2.6 and 3.gold, I'd advocate removing
> the pre-defined 'bytes', or maybe defining it as something else.

I think it needs to be made clear that bytes is there for type
compatibility (e.g., ``isinstance(ob, bytes)``). And the bytes
literals work how you would expect.

What I would like to know if there are any other gotchas beyond the
constructor as all of the other uses act as you would expect.

-Brett
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to