python snippet
Write a text file
Create or overwrite a UTF-8 file with a newline.
from pathlib import Pathpath = Path("data/output.txt")# Overwrite existing contentpath.write_text("Hello, world!\n", encoding="utf-8")# Append instead of overwritewith path.open("a", encoding="utf-8") as fh:fh.write("Another line\n")