(path: str | pathlib.Path, data: str | list[str])
| 788 | |
| 789 | |
| 790 | def write_lines(path: str | pathlib.Path, data: str | list[str]): |
| 791 | if isinstance(data, str): |
| 792 | data = [data] |
| 793 | data = [row + "\n" for row in data] |
| 794 | |
| 795 | with tempfile.NamedTemporaryFile(mode="w+", delete=False) as f: |
| 796 | f.writelines(data) |
| 797 | tmp_path = f.name |
| 798 | # Move is atomic in POSIX filesystems, that makes the whole write atomic as a result |
| 799 | os.replace(tmp_path, path) |
| 800 | |
| 801 | |
| 802 | def read_lines(path: str | pathlib.Path) -> list[str]: |