Byte oriented data types in python

Ravi ra.ravi.rav at gmail.com
Sun Jan 25 16:28:05 CET 2009


On Jan 25, 12:52 am, "Martin v. Löwis" <mar... at v.loewis.de> wrote:
> > 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()).

This looks really helpful thanks!




More information about the Python-list mailing list