Module: utils.tempdir
This module contains classes - NamedFileInTemporaryDirectory, TemporaryWorkingDirectory.
These classes add extra features such as creating a named file in temporary directory and creating a context manager for the working directory which is also temporary.
2 Classes
- class IPython.utils.tempdir.NamedFileInTemporaryDirectory(filename: str, mode: str, bufsize: int = -1, add_to_syspath: bool = False, **kwds)
Bases:
object- __init__(filename: str, mode: str, bufsize: int = -1, add_to_syspath: bool = False, **kwds)
Open a file named
filenamein a temporary directory.This context manager is preferred over
NamedTemporaryFilein stdlibtempfilewhen one needs to reopen the file.Arguments
modeandbufsizeare passed toopen. Rest of the arguments are passed toTemporaryDirectory.
- class IPython.utils.tempdir.TemporaryWorkingDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False, *, delete=True)
Bases:
TemporaryDirectoryCreates a temporary directory and sets the cwd to that directory. Automatically reverts to previous cwd upon cleanup. Usage example:
- with TemporaryWorkingDirectory() as tmpdir:
…