Binary list class, strings or longs?

Remco Gerlich scarblac at pino.selwerd.nl
Wed Jan 17 09:32:48 EST 2001


vague <msandin at remove_this.hotmail.com> wrote in comp.lang.python:
> Is there anyone who knows if there's a class somewhere that lets me handle
> binary objects/streams in Python in a simple way? One possible
> implementation would be to have it wrap the string type. I'd like to be able
> to perform binary arithmetics on arbitary parts of the objects (as in not
> only on byte boundaries or on byte lengths). I would have use for it for
> image manipulation in combining bitmasks.

You want to store the binary stream as a string, and then use the struct
module to translate parts of it to integers and back. You can only do the
arithmetic on numbers, but the struct module can translate bytes from a
string quickly. See the library reference.

Depending on what you want to do, it might be easier to simply use the
Python Imaging Library, http://www.secretlabs.com/products/pil/index.htm .

And lastly, maybe NumPy is easier for applying a filter to a large matrix of
data, but I don't know, never used it. Something to keep in mind though.

-- 
Remco Gerlich



More information about the Python-list mailing list