tempfile.TemporaryDirectory()
tempfile.TemporaryDirectory() is a Python function in the Tempfile Module category. Creates a temporary directory that is automatically cleaned up when closed. The syntax is tempfile.TemporaryDirectory(suffix=None, prefix=None, dir=None). Returns: Directory path (context manager). A typical example: with tempfile.TemporaryDirectory() as d:
print(d) # "/tmp/tmpXXXXXX/"
# Directory and contents deleted after with block. A close sibling is tempfile.TemporaryFile(), which creates a temporary file that is automatically deleted when closed. A close sibling is tempfile.NamedTemporaryFile(), which creates a temporary file with a visible name in the filesystem. A close sibling is tempfile.mkstemp(), which creates a temporary file and returns a (fd, path) tuple. Caller must close and delete. A close sibling is tempfile.mkdtemp(), which creates a temporary directory that persists after creation. More about this category: Temporary file and directory creation — TemporaryFile, mkstemp, mkdtemp. Related Tempfile Module entries: tempfile.TemporaryFile(), tempfile.NamedTemporaryFile(), tempfile.mkstemp(), tempfile.mkdtemp(), tempfile.gettempdir(), tempfile.tempdir.