1

the function :

    f = open('image.txt', 'wb')
    byte_arr = getbytes(read_bits())
    byte_list = list(byte_arr)
    print(byte_list)
    some_bytes = bytearray(byte_list)
    print(bytes(some_bytes))
    st = bytes(some_bytes).decode('latin1')
    immutable_bytes = bytes(some_bytes)
    with open('test','wb') as f:
         f.write(immutable_bytes )

the output is like :

b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00'

what I want is to write string value converted from this list of byte values

sjakobi
  • 3,436
  • 1
  • 22
  • 42

1 Answers1

1

You could try this:

st = bytes(some_bytes).decode('utf-8')
with open('test','wb') as f:
     f.write(st)

instead of this:

st = bytes(some_bytes).decode('latin1')
immutable_bytes = bytes(some_bytes)
with open('test','wb') as f:
     f.write(immutable_bytes )