[Python-3000] PEP 3137: Immutable Bytes and Mutable Buffer (original) (raw)

Alexandre Vassalotti alexandre at peadrop.com
Thu Sep 27 17:13:38 CEST 2007


On 9/26/07, Alexandre Vassalotti <alexandre at peadrop.com> wrote:

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.

I didn't known about the length-1 comparison issue when I wrote this. Personally, I wouldn't mind writing either this:

for b in bytes: if b == b'a'[0]: pass

or this:

for b in bytes: if b == b'a': pass

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).

I don't think my argument is still valid. Compared the use of ord() in Python 2.x vs. Python 3.x with:

% egrep -R --include='.py' '<ord(' python/Lib | wc -l 238 % egrep -R --include='.py' '<ord(' py3k/Lib | wc -l 221

I thought ord() was mostly used for extracting ints from a string object variable. I was wrong about that. ord() is most often used for getting an int value from a length-1 string constant.

So, I am neutral about the whole indexing issue. Either indexing behavior has advantages and disadvantages, so it will be difficult to choose which is better.

-- Alexandre



More information about the Python-3000 mailing list