I have following packet format which I have to send over Bluetooth. > > 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.
Check out the struct module. You want something like: data = struct.pack("BB4s", 1, 4, "this") It returns a string of bytes according to the specification -- B is unsigned byte, and "4s" is a string of 4 characters. The 1 feeds into the first byte, the 4 into the second, etc. --Stephen
-- http://mail.python.org/mailman/listinfo/python-list