Re: [Python-3000] bytes: compare bytes to integer

2007-08-18 Thread Greg Ewing
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:

Re: [Python-3000] bytes: compare bytes to integer

2007-08-18 Thread Guido van Rossum
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

Re: [Python-3000] bytes: compare bytes to integer

2007-08-18 Thread Nick Coghlan
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')

Re: [Python-3000] bytes: compare bytes to integer

2007-08-14 Thread Barry Warsaw
-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: >

Re: [Python-3000] bytes: compare bytes to integer

2007-08-12 Thread Victor Stinner
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

Re: [Python-3000] bytes: compare bytes to integer

2007-08-12 Thread Greg Ewing
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

Re: [Python-3000] bytes: compare bytes to integer

2007-08-12 Thread Georg Brandl
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:

Re: [Python-3000] bytes: compare bytes to integer

2007-08-12 Thread Bill Janssen
> 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