[Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer (original) (raw)
Georg Brandl g.brandl at gmx.net
Thu Sep 27 08:15:00 CEST 2007
- Previous message: [Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
- Next message: [Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Alexandre Vassalotti schrieb:
Indexing --------
Open Issue: I'm undecided on whether indexing bytes and buffer objects should return small ints (like the bytes type in 3.0a1, and like lists or array.array('B')), or bytes/buffer objects of length 1 (like the str type). The latter (str-like) approach will ease porting code from Python 2.x; but it makes it harder to extract values from a bytes array. I think indexing a bytes/buffer object should return an int. I find this behavior more natural, to me, than using an ord()-like function to extract values. In fact, I remarked that the use of ord() is good indicator that bytes should be used instead of str (look by yourself: grep -R --include='*.py' 'ord(' python25/Lib).
If b[0] returns an int, you will have to use ord() to compare it to b"a". If it returns b"a", you won't.
If you want to compare a byte by ordinal, you can still use b"\xAB", without a function call...
Therefore I vote for returning not an int, but I wouldn't object to bytes of length 1 being comparable to ints.
Georg
-- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.
- Previous message: [Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
- Next message: [Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]