Nov-02-2021, 08:55 PM
I would rather do it this way
>>> import io >>> f = io.BytesIO(b'foo bar baz') >>> L = [bin(c)[2:] for c in f.read()] >>> L ['1100110', '1101111', '1101111', '100000', '1100010', '1100001', '1110010', '100000', '1100010', '1100001', '1111010'] >>> b = bytes([int(s, 2) for s in L]) >>> b b'foo bar baz'