struct.unpack on a bytearray that works under Python 2.6.6, 2.7 and 3.3?
Why not just call bytes?

number = struct.unpack('&lt;I', bytes(buf))[0]


In Python 2.6:

Python 2.6.8 (unknown, Aug 13 2012, 22:19:05) 
...
&gt;&gt;&gt; import struct
&gt;&gt;&gt; struct.unpack('&lt;I', bytes(bytearray(b'ABCD')))
(1145258561,)


In Python 3.3:

Python 3.3.2 (default, May 21 2013, 11:50:47) 
...
&gt;&gt;&gt; import struct
&gt;&gt;&gt; struct.unpack('&lt;I', bytes(bytearray(b'ABCD')))
(1145258561,)