In [1]: int('10011001',2) Out[1]: 153
Divide your input into pieces of eight bits, then apply int(_, 2) and chr , then concatenate into a line and write that line to a file.
Sort of...:
your_file.write(''.join(chr(int(your_input[8*k:8*k+8], 2)) for k in xrange(len(your_input)/8)))
liori source share