ID EN
Pathlib

write_bytes

Python 3.11

Open the file pointed to in bytes mode, write data to it, and close the file:

Syntax

PYTHON
Path.write_bytes(data)

Examples

Example 1
PYTHON
>>> p = Path('my_binary_file')
>>> p.write_bytes(b'Binary file contents')
20
>>> p.read_bytes()
b'Binary file contents'