Write bits in file

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun May 18 11:05:41 EDT 2008


En Sun, 18 May 2008 10:36:28 -0300, Monica Leko <monica.leko at gmail.com> escribió:

> On May 18, 2:20 pm, Ken Starks <stra... at lampsacos.demon.co.uk> wrote:
>> You want your file considered as a sequence of bits rather
>> than a sequence of 8-bit bytes, do you?
>
> Yes.
>
>> is the 10-bit
>> bit-pattern to be stored at an arbitrary bit-position in
>> the file
>
> Yes.  I need arbitrary, 8bits, than 10 bits for something else, than
> sequence of bytes, than 10 bits again, etc.

If you really need arbitrary bit sequences that aren't synchonized into bytes, I think there is a BitVector o BitArray package somewhere.
But if you mostly have bytes and sparsely a different size, I think the struct module and some gymnastics involving bitwise operations would be enough.

-- 
Gabriel Genellina




More information about the Python-list mailing list