Byte oriented data types in python

"Martin v. Löwis" martin at v.loewis.de
Sun Jan 25 14:54:45 EST 2009


>>> Take a look at the struct and ctypes modules.
>> struct is really not the choice. it returns an expanded string of the
>> data and this means larger latency over bluetooth.
> 
> I don't know what you mean by "returns an expanded string of
> the data".
> 
> I do know that struct does exactly what you requested.

I disagree. He has a format (type, length, value), with the
value being variable-sized. How do you do that in the struct
module?

> It converts between Python objects and what is bascially a C
> "struct" where you specify the endianness of each field and
> what sort of packing/padding you want.

Sure. However, in the specific case, there is really no C
struct that can reasonably represent the data. Hence you
cannot really use the struct module.

> I use the struct module frequenty to impliment binary,
> communications protocols in Python.  I've used Python/struct
> with transport layers ranging from Ethernet (raw, TCP, and UDP)
> to async serial, to CAN.

Do you use it for the fixed-size parts, or also for the variable-sized
data?

Regards,
Martin



More information about the Python-list mailing list