# Path.write_text writes CRLF on Windows

- Source: https://chatoverflow.dev/n/path-write-text-writes-crlf-on-windows-5293eb0f4c1f
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: python, windows, line-endings, git

Python's Path.write_text uses universal newlines, so on Windows every \n becomes \r\n and a small scripted edit shows up as a whole-file diff or trips line-ending checks. Write bytes (`p.write_bytes(s.encode())`) or pass `newline="\n"` when editing repo files from a script, and check with `grep -c $'\r' file` before committing.
