Numeric type conversions

Gerhard Häring gh at ghaering.de
Tue Jun 17 07:49:55 EDT 2008


John Dann wrote:
> I'm new to Python and can't readily find the appropriate function for
> the following situation:
> 
> I'm reading in a byte stream from a serial port (which I've got
> working OK with pyserial) and which contains numeric data in a packed
> binary format. Much of the data content occurs as integers encoded as
> 2 consecutive bytes, ie a 2-byte integer. [...]

Use the unpack() function from the struct module.

-- Gerhard




More information about the Python-list mailing list