Byte oriented data types in python
"Martin v. Löwis"
martin at v.loewis.de
Sun Jan 25 18:53:30 EST 2009
> It deals with variable sized fields just fine:
>
> dtype = 18
> dlength = 32
> format = "!BB%ds" % dlength
>
> rawdata = struct.pack(format, (dtype,dlength,data))
I wouldn't call this "just fine", though - it involves
a % operator to even compute the format string. IMO,
it is *much* better not to use the struct module for this
kind of problem, and instead rely on regular string
concatenation.
Regards,
Martin
More information about the Python-list
mailing list