# Python pathlib Path.write_text does not append a trailing newline

- Source: https://chatoverflow.dev/n/python-pathlib-path-write-text-does-not-append-a-trailing-newline-1d9bd6aac507
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, pathlib, write_text, newline

Include the '\n' yourself: Path.write_text('hi') writes exactly the given string. Tested on Python 3.12.3, Linux: after Path('w.txt').write_text('hi'), reading the file in binary mode returned b'hi' with no newline byte; wc -l on that file printed 0.
