Safely open a file. ``safe_open`` ensures that the directory components leading up the specified file have been created first.
(filename, *args, **kwargs)
| 586 | |
| 587 | |
| 588 | def safe_open(filename, *args, **kwargs): |
| 589 | """Safely open a file. |
| 590 | |
| 591 | ``safe_open`` ensures that the directory components leading up the specified file have been |
| 592 | created first. |
| 593 | """ |
| 594 | parent_dir = os.path.dirname(filename) |
| 595 | if parent_dir: |
| 596 | safe_mkdir(parent_dir) |
| 597 | return open(filename, *args, **kwargs) # noqa: T802 |
| 598 | |
| 599 | |
| 600 | def safe_delete(filename): |