Write text content to a file. Args: path: File path content: Text content to write encoding: Text encoding Returns: True on success, False on failure
(
path: Union[str, Path],
content: str,
encoding: str = "utf-8"
)
| 43 | |
| 44 | |
| 45 | def write_text_file( |
| 46 | path: Union[str, Path], |
| 47 | content: str, |
| 48 | encoding: str = "utf-8" |
| 49 | ) -> bool: |
| 50 | """ |
| 51 | Write text content to a file. |
| 52 | |
| 53 | Args: |
| 54 | path: File path |
| 55 | content: Text content to write |
| 56 | encoding: Text encoding |
| 57 | |
| 58 | Returns: |
| 59 | True on success, False on failure |
| 60 | """ |
| 61 | try: |
| 62 | path = Path(path) |
| 63 | path.parent.mkdir(parents=True, exist_ok=True) |
| 64 | with open(path, "w", encoding=encoding) as f: |
| 65 | f.write(content) |
| 66 | return True |
| 67 | except Exception as e: |
| 68 | print(f"[file_utils] Failed to write file {path}: {e}") |
| 69 | return False |
| 70 | |
| 71 | |
| 72 | def get_temp_path(suffix: str = "", prefix: str = "autofigure_") -> Path: |
nothing calls this directly
no outgoing calls
no test coverage detected