Reading file bit by bit
Terry Reedy
tjreedy at udel.edu
Mon Jun 7 14:58:00 EDT 2010
On 6/7/2010 6:20 AM, Ulrich Eckhardt wrote:
> Ulrich Eckhardt wrote:
>> data = f.read()
>> for byte in data:
>> for i in range(8):
>> bit = 2**i& byte
>> ...
>
> Correction: Of course you have to use ord() to get from the single-element
> string ("byte" above) to its integral value first.
In Py3 (OP did not specify), a binary file is read as bytes, which is a
sequence of ints, and one would have to not use ord() ;=)
tjr
More information about the Python-list
mailing list