pack heterogeneous data types

Jp Calderone exarkun at divmod.com
Wed Jun 8 17:55:04 EDT 2005


On 8 Jun 2005 14:49:00 -0700, ashokbellur at gmail.com wrote:
>Hello,
>
>How do i pack different data types into a struct or an array. Examples
>would be helpful.
>
>Say i need to pack an unsigned char( 0xFF) and an long( 0xAAAAAAAA)
>into a single array? The reason i need to do this is send a packet over
>a network.

    >>> import struct
    >>> struct.pack('!BL', 0xff, 0xaaaaaaaa)
    '\xff\xaa\xaa\xaa\xaa'
    >>>

Jp



More information about the Python-list mailing list