[Python-3000] bytes: compare bytes to integer

Victor Stinner victor.stinner at haypocalc.com
Mon Aug 13 02:19:56 CEST 2007


On Sunday 12 August 2007 19:11:18 Bill Janssen wrote:
> Why not just write
>> b'xyz'[0:1] == b'x'

It's just strange to write:
 'abc'[0] == 'a'
for character string and:
 b'abc'[0:1] == b'a'
for byte string.
The problem in my brain is that str is a special case since a str item is also 
a string, where a bytes item is an integer.
It's clear that "[5, 9, 10][0] == [5]" is wrong, but for bytes and str it's 
not intuitive because of b'...' syntax. If I had to wrote [120, 121, 122] 
instead of b'xyz' it would be easier to understand that first value is an 
integer and not the *letter* X or the *string* X.
I dislike b'xyz'[0:1] == b'x' since I want to check first item and not to 
compare substrings.
Victor Stinner aka haypo
http://hachoir.org/


More information about the Python-3000 mailing list

AltStyle によって変換されたページ (->オリジナル) /