There's a python module especially made for reading and writing to and from binary encoded data called 'struct'. Since versions of Python under 2.6 doesn't support str.format, a custom method needs to be used to create binary formatted strings.
import struct
# binary string
def bstr(n): # n in range 0-255
return ''.join([str(n >> x & 1) for x in (7,6,5,4,3,2,1,0)])
# read file into an array of binary formatted strings.
def read_binary(path):
f = open(path,'rb')
binlist = []
while True:
bin = struct.unpack('B',f.read(1))[0] # B stands for unsigned char (8 bits)
if not bin:
break
strBin = bstr(bin)
binlist.append(strBin)
return binlist