Context manager for temporary files. Context manager that returns the path to a closed temporary file. Its parameters are the same as for tempfile.mkstemp and are passed directly to that function. The underlying file is removed when the context is exited, so it should be closed at t
(*args, **kwargs)
| 2202 | |
| 2203 | @contextlib.contextmanager |
| 2204 | def temppath(*args, **kwargs): |
| 2205 | """Context manager for temporary files. |
| 2206 | |
| 2207 | Context manager that returns the path to a closed temporary file. Its |
| 2208 | parameters are the same as for tempfile.mkstemp and are passed directly |
| 2209 | to that function. The underlying file is removed when the context is |
| 2210 | exited, so it should be closed at that time. |
| 2211 | |
| 2212 | Windows does not allow a temporary file to be opened if it is already |
| 2213 | open, so the underlying file must be closed after opening before it |
| 2214 | can be opened again. |
| 2215 | |
| 2216 | """ |
| 2217 | fd, path = mkstemp(*args, **kwargs) |
| 2218 | os.close(fd) |
| 2219 | try: |
| 2220 | yield path |
| 2221 | finally: |
| 2222 | os.remove(path) |
| 2223 | |
| 2224 | |
| 2225 | class clear_and_catch_warnings(warnings.catch_warnings): |
searching dependent graphs…