[Python-Dev] Python 3.x and bytes

Ethan Furman ethan at stoneleaf.us
Wed May 18 00:27:45 CEST 2011


The bytes type in Python 3 does not feel very consistent.

For example:

--> some_var = 'abcdef'
--> some_var
'abcdef'
--> some_var[3]
'd'
--> some_other_var = b'abcdef'
--> some_other_var
b'abcdef'
--> some_other_var[3]
100


On the one hand we have the 'bytes are ascii data' type interface, and 
on the other we have the 'bytes are a list of integers between 0 - 256' 
interface.  And trying to use the two is not intuitive:

--> some_other_var[3] == b'd'
False

When I'm parsing a .dbf file and extracting field types from the byte 
stream, I'm not thinking, "okay, 67 is a Character field" -- what I'm 
thinking is, "b'C' is a Character field".

Considering that ord() still works fine, I'm not sure why it was done 
this way.

Is there code out there that is using this "list of int's" interface, or 
is there time to make changes to bytes?

~Ethan~


More information about the Python-Dev mailing list