[Python-3000] bytes: compare bytes to integer
Victor Stinner
victor.stinner at haypocalc.com
Sat Aug 11 02:25:27 CEST 2007
Hi,
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!
Victor Stinner aka haypo
http://hachoir.org/
More information about the Python-3000
mailing list