gui.model.write_text_file(path, text, overwrite=True)
Write a text file as UTF-8, the way spotregen context -o does.
Parameters
| path |
Path |
The file. Missing parent directories are created. |
required |
| text |
str |
The content, written unchanged. |
required |
| overwrite |
bool |
Whether an existing file is replaced, as context -o does. The interface passes False and never overwrites. |
True |
Raises
|
FileExistsError |
If the file exists and overwrite is False; it is untouched. |
Examples
from pathlib import Path
from tempfile import TemporaryDirectory
from spotregen.gui.model import write_text_file
with TemporaryDirectory() as tmp:
target = write_text_file(Path(tmp) / "runs" / "context.md", "Zürich")
print(target.read_bytes())