Python Tempfile Module
Temporary file and directory creation — TemporaryFile, mkstemp, mkdtemp. This category documents 7 Python tempfile module entries, and each page gives you the full syntax, the parameter list, the return value, and a runnable example. The entries include: tempfile.TemporaryFile(), tempfile.NamedTemporaryFile(), tempfile.mkstemp(), tempfile.mkdtemp(), tempfile.TemporaryDirectory(), tempfile.gettempdir(), tempfile.tempdir. tempfile.TemporaryFile() creates a temporary file that is automatically deleted when closed. tempfile.NamedTemporaryFile() creates a temporary file with a visible name in the filesystem. tempfile.mkstemp() creates a temporary file and returns a (fd, path) tuple. Caller must close and delete. tempfile.mkdtemp() creates a temporary directory that persists after creation. tempfile.TemporaryDirectory() creates a temporary directory that is automatically cleaned up when closed. Tempfile Module belongs to the File & Data group alongside Pathlib Module, Shutil Module, Glob Module, Fileinput Module. You can also search across every category from the search page, browse the complete A–Z index, or try any example in the Python playground.