Byte oriented data types in python

"Martin v. Löwis" martin at
Sat Jan 24 20:52:15 CET 2009

> packet_type (1 byte unsigned) || packet_length (1 byte unsigned) ||
> packet_data(variable)
> How to construct these using python data types, as int and float have
> no limits and their sizes are not well defined.

In Python 2.x, use the regular string type: chr(n) will create a single
byte, and the + operator will do the concatenation.

In Python 3.x, use the bytes type (bytes() instead of chr()).


More information about the Python-list mailing list