[Python-3000] bytes: compare bytes to integer
Bill Janssen
janssen at parc.com
Sun Aug 12 19:11:18 CEST 2007
> I don't like the behaviour of Python 3000 when we compare a bytes strings
> with length=1:
> >>> b'xyz'[0] == b'x'
> False
>
> The code can be see as:
> >>> ord(b'x') == b'x'
> False
>
> or also:
> >>> 120 == b'x'
> False
>
> Two solutions:
> 1. b'xyz'[0] returns a new bytes object (b'x' instead of 120)
> like b'xyz'[0:1] does
> 2. allow to compare a bytes string of 1 byte with an integer
>
> I prefer (2) since (1) is wrong: bytes contains integers and not bytes!
Why not just write
b'xyz'[0:1] == b'x'
in the first place? Let's not start adding "special" cases.
Bill
More information about the Python-3000
mailing list