[Tutor] Concatenating numeric data in Python 3.3

eryksun eryksun at gmail.com
Thu Apr 25 01:23:49 CEST 2013


On Wed, Apr 24, 2013 at 4:21 PM, Prasad, Ramit
<ramit.prasad at jpmorgan.com> wrote:
> Your struct.pack() line seems fine, but you might want to specify
> endian-ness as the default value may vary by architecture.
> (See http://en.wikipedia.org/wiki/Endian )
>
>>>> struct.pack('>HBB', 1234,1,0 )
> '\x04\xd2\x01\x00' # note location of 4 and d2
>>>> struct.pack('<HBB', 1234,1,0 )
> '\xd2\x04\x01\x00' # note location of 4 and d2 are swapped

struct.pack returns bytes in 3.x, not a string as shown above.
Remember to use b''.join instead of ''.join if the groups are being
joined into a larger buffer.


More information about the Tutor mailing list