Pyhon 2.x or 3.x, which is faster?

Terry Reedy tjreedy at udel.edu
Mon Mar 7 22:51:50 EST 2016


On 3/7/2016 7:22 PM, BartC wrote:

> (Is a byte string the same as a byte array?

No, if by 'byte array' mean (mutable) bytearray.
Yes, in the sense that a byte string is an (immutable) array of ints in 
range(256).

> Is a byte array the same as an array.array?
No, if by 'byte array' you mean the same as bytes.
Yes, if you mean bytearray and array.array('B'), in the sense that 
bytearray is based on array.array('B').


> If I remove this line from my code, where 'data' has
 > just been read from a file:
>
>     data=array.array('B',data)
>
> then it still works - Python 3.

In 3.3, data = bytearray(data) would have the same effect, and the only 
effect is to make data mutable, but if you do not mutate the image 
bytes, that is useless.

-- 
Terry Jan Reedy




More information about the Python-list mailing list