temp_file - Temporary files that support the context protocol

Temporary files and directories.

Requires at least Python 2.6

class TempDir(*args, **kwargs)[source]

A temporary directory that implements the context manager protocol.

The directory is removed when the context is exited from. Uses tempfile.mkdtemp() to create the actual directory.

__init__(*args, **kwargs)[source]

Create a temporary directory with the given arguments.

name

Return the directory name.

class TempFile(*args, **kwargs)[source]

A temporary file that implements the context manager protocol.

Wrap a tempfile.NamedTemporaryFile() generated file-like object, to ensure it is not deleted on close, but rather when the underlying context is closed.

__init__(*args, **kwargs)[source]

Create a temporary file with the given arguments.

name

Return the actual file name.