Answers for "python save file bytes"

0

im save to a bytes io python

from io import BytesIO
from PIL import Image, ImageDraw

image = Image.new("RGB", (300, 50))
draw = ImageDraw.Draw(image)
draw.text((0, 0), "This text is drawn on image")

byte_io = BytesIO()

image.save(byte_io, 'PNG')
Posted by: Guest on August-11-2020
0

Writing Bytes to a File in python

# Pass "wb" to write a new file, or "ab" to append
with open("test.txt", "wb") as binary_file:
    # Write text or bytes to the file
    binary_file.write("Write text by encodingn".encode('utf8'))
    num_bytes_written = binary_file.write(b'xDExADxBExEF')
    print("Wrote %d bytes." % num_bytes_written)
Posted by: Guest on December-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language