tempfile

Stdlib — OS/FilePython 2.0+Intermediate

Create temporary files and directories that auto-clean up

Quick Info

Documentation
Official Docs
Python Version
2.0+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import tempfile

# Create temporary file
with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f:
    f.write("Temporary data")
    print(f"Temp file: {f.name}")

The tempfile module is part of Python's standard library. Create temporary files and directories that auto-clean up.

Try in Playground

Tags

stdlibfile-iotemporarycleanup

Related Items