[Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer
g.brandl at gmx.net
Thu Sep 27 08:15:00 CEST 2007
Alexandre Vassalotti schrieb:
>> **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 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.
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.
More information about the Python-3000