gui.model.write_text_file

gui.model.write_text_file(path, text, overwrite=True)

Write a text file as UTF-8, the way spotregen context -o does.

Parameters

Name Type Description Default
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

Returns

Name Type Description
Path Path path.

Raises

Name Type Description
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())
b'Z\xc3\xbcrich'