Dev HelpersOpen library
← Back

Read and write UTF-8 text

Read and write UTF-8 text. 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) / 'note.txt'
    p.write_text('hello café', encoding='utf-8')
    print(p.read_text(encoding='utf-8'))

Sample output

hello café