Open the file in text mode, write to it, and close the file.
>>> p = Path('my_text_file') >>> p.write_text('Text file contents') 18 >>> p.read_text() 'Text file contents'
pathlib/Path.write_text
Path.write_text