Dev HelpersOpen library
← Back

Write binary bytes

Write binary bytes. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

from tempfile import TemporaryDirectory
from pathlib import Path
with TemporaryDirectory() as folder:
    p = Path(folder) / 'data.bin'
    p.write_bytes(bytes([0, 128, 255]))
    print(list(p.read_bytes()))

Sample output

[0, 128, 255]