tempfile
The standard library module for creating temporary files and folders that are cleaned up automatically.
In more detail
tempfile.TemporaryDirectory() used in a with statement gives a scratch folder that disappears afterwards, which is handy in tests. Temporary files are created somewhere safe that other programs will not collide with.
Related terms
- with statement — A statement that sets something up, runs a block, and guarantees the matching clean-up afterwards, most often closing a file.
- pathlib — Python's standard library module for working with file paths as objects rather than plain strings.
Taught in
- A Standard Library Tour — Hands-on Python: Complete Video Course & Book