from PIL import Image img = Image.open('some/file.png') img = img.convert(mode='1') imgbytes = img.tobytes() with open('filepath', 'w') as file_out: file_out.write(imgbytes) I would like to write the sequence of bytes in imgbytes, as a string preceded with b', to a file. I don't need to encode it. write() doesn't accept bytes nor bytearray parameters. Continue reading...