Nick Coghlan wrote:
>bytes_obj[0] == ord('x')
That's a rather expensive way of comparing an
integer with a constant, though.
--
Greg
___
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
On 8/18/07, Nick Coghlan <[EMAIL PROTECTED]> wrote:
> Victor Stinner wrote:
> > 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'
> >Fals
Victor Stinner wrote:
> 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
This seems to suggest its own solution:
bytes_obj[0] == ord('x')
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
On Aug 12, 2007, at 1:41 PM, Georg Brandl wrote:
> Bill Janssen schrieb:
>>> 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:
>
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
Georg Brandl wrote:
> Hm... I have a feeling that this will be one of the first entries in a
> hypothetical "Python 3.0 Gotchas" list.
And probably it's exacerbated by calling them byte
"strings", when they're really a kind of array rather
than a kind of string, and the use of b"..." as a
construc
Bill Janssen schrieb:
>> 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:
> 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