arrays - Converting String of Zero's and One's to binary byte Python -


i have code using convert file bytes bytes strings of 0's , 1's.

with open(file, mode='rb') file: content = file.read() b = bytearray(content)  number in b:     data = bin(number)[2:].zfill(8)     print data 

i output 10110100, 00000001, etc, etc should be.

i want take strings of bits in output , convert them bytes, write bytes new file.

i have tried following code:

list = ('11111111', '11111110', '01101000', '00000000', '01101001', '00000000', '00001101', '00000000', '00001010', '00000000') def writer(stuff):     blob = struct.pack('!h', int(stuff, 2))     open('test.txt', "a+b") file:             file.write(blob) strings in list:     writer(strings) 

the original text file contains word "hi" , all, when write new file output "▒▒hi"


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -