ID EN
Pathlib

read_text

Python 3.11

Return the decoded contents of the pointed-to file as a string:

Syntax

PYTHON
Path.read_text(encoding=None, errors=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()