TemporaryDirectory class, copied from Python 3.2.
This is copied from the stdlib and will be standard in Python 3.2 and onwards.
TemporaryDirectory(suffix=None, prefix=None, dir=None)¶
Create and return a temporary directory. This has the same behavior as mkdtemp but can be used as a context manager. For .. rubric:: Example
- with TemporaryDirectory() as tmpdir:
Upon exiting the context, the directory and everything contained in it are removed.
__init__(suffix=None, prefix=None, dir=None)¶
Initialize self. See help(type(self)) for accurate signature.
NamedFileInTemporaryDirectory(filename, mode='w+b', bufsize=-1, **kwds)¶
__init__(filename, mode='w+b', bufsize=-1, **kwds)¶
Open a file named
filenamein a temporary directory.
This context manager is preferred over
tempfilewhen one needs to reopen the file.
bufsizeare passed to
open. Rest of the arguments are passed to
TemporaryWorkingDirectory(suffix=None, prefix=None, dir=None)¶
Creates a temporary directory and sets the cwd to that directory. Automatically reverts to previous cwd upon cleanup. Usage example:
- with TemporaryWorkingDirectory() as tmpdir: