| Conditions | 4 |
| Total Lines | 13 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 31 | def write_file(filepath, content): |
||
| 32 | # https://stackoverflow.com/questions/12517451/automatically-creating-directories-with-file-output |
||
| 33 | if not os.path.exists(os.path.dirname(filepath)): |
||
| 34 | try: |
||
| 35 | os.makedirs(os.path.dirname(filepath)) |
||
| 36 | except OSError as e: |
||
| 37 | # Guard against race condition |
||
| 38 | if e.errno != errno.EEXIST: |
||
| 39 | raise e |
||
| 40 | handler = open(filepath, 'w+') |
||
| 41 | handler.write(content) |
||
| 42 | handler.close() |
||
| 43 | return True |
||
| 44 |