Need to convert an arbitrary byte-pair to an int.

Graham Nicholls graham at rockcons.co.uk
Thu Aug 7 08:15:08 EDT 2003


Richard Brodie wrote:

> 
> "Graham Nicholls" <graham at rockcons.co.uk> wrote in message
> news:3f323dc2$0$10775$afc38c87 at auth.uk.news.easynet.net...
> 
>> I'm trying to size a jpeg file.  The file size is held in a short (2 byte
>> integer) at a certain offset.  Once I've found these two bytes (they're
>> in MSB,LSB order), I need to convert them to an integer - now I know that
>> in C I'd just cast a pointer to the offset to a short, and that python
>> doesn't
>> cast, so how can I extract the value from a stream of bytes.  I've looked
>> at python.org/Doc/current (I'm using 2.3b1), but can't find anything
>> obvious.
> 
> For rolling your own direct handling of byte streams, the struct module is
> often best. You also might want to look at the Python Imaging Library
> http://www.pythonware.com/products/pil/

Thanks - that looks to be exactly what I need.
-- 
Graham Nicholls
Rock Computer Consultancy





More information about the Python-list mailing list