Context manager that temporarily creates and changes the CWD. The function temporarily changes the current working directory after creating a temporary directory in the current directory with name *name*. If *name* is None, the temporary directory is created using tempfile.mkd
(name='tempcwd', quiet=False)
| 580 | |
| 581 | @contextlib.contextmanager |
| 582 | def temp_cwd(name='tempcwd', quiet=False): |
| 583 | """ |
| 584 | Context manager that temporarily creates and changes the CWD. |
| 585 | |
| 586 | The function temporarily changes the current working directory |
| 587 | after creating a temporary directory in the current directory with |
| 588 | name *name*. If *name* is None, the temporary directory is |
| 589 | created using tempfile.mkdtemp. |
| 590 | |
| 591 | If *quiet* is False (default) and it is not possible to |
| 592 | create or change the CWD, an error is raised. If *quiet* is True, |
| 593 | only a warning is raised and the original CWD is used. |
| 594 | |
| 595 | """ |
| 596 | with temp_dir(path=name, quiet=quiet) as temp_path: |
| 597 | with change_cwd(temp_path, quiet=quiet) as cwd_dir: |
| 598 | yield cwd_dir |
| 599 | |
| 600 | |
| 601 | def create_empty_file(filename): |