ID EN
Pathlib

write_text

Python 3.11

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

Syntax

PYTHON
Path.write_text(data, encoding=None, errors=None, newline=None)

Examples

Example 1
PYTHON
>>> p = Path('my_text_file')
>>> p.write_text('Text file contents')
18
>>> p.read_text()
'Text file contents'

See Also

open()