About data structure
Martin v. Loewis
martin at v.loewis.de
Mon Sep 30 15:39:00 EDT 2002
malan <malan at club-internet.fr> writes:
> I need to build a data structure like this :
>
> size 4 bytes ( example 0x0000000A )
> flag 1 byte ( example 0x87 )
> trans 8 bytes ( example 'URTVMI1' )
> F5 3 bytes ( example 0x00125C )
>
> How can I define that structure, format it and send it via a socket ?
Your specification is incomplete, as you don't give the byte
order. Assuming it has to be big-endian, that would be
>>> import struct
>>> struct.pack(">IB8s3b", 0xA, 0x87, "URTVMI1", 0x0, 0x12, 0x5c)
'\x00\x00\x00\n\x87URTVMI1\x00\x00\x12\\'
For details, help(struct).
HTH,
Martin
More information about the Python-list
mailing list