Numeric type conversions

Gerhard Häring gh at
Tue Jun 17 13:49:55 CEST 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