tempdir
raw JSON → 0.7.1 verified Mon Apr 27 auth: no python maintenance
A simple library providing temporary directory contexts, wrapping tempfile.mkdtemp. Current version 0.7.1, low activity.
pip install tempdir Common errors
error ModuleNotFoundError: No module named 'tempdir' ↓
cause tempdir not installed or environment issue
fix
pip install tempdir
error AttributeError: module 'tempdir' has no attribute 'TempDir' ↓
cause Wrong import: import tempdir then using tempdir.TempDir
fix
Use: from tempdir import TempDir
error tempdir.TempDir is deprecated ↓
cause tempdir library not standard library; standard library's tempfile has TemporaryDirectory
fix
Use: from tempfile import TemporaryDirectory
Warnings
gotcha TempDir creates a new directory each time; the directory is not reused. Do not rely on the path being predictable. ↓
fix Use the returned TempDir object's .name attribute for the path.
gotcha TempDir does not set permissions; directory permissions are inherited from umask. Might be world-readable if umask is permissive. ↓
fix Set umask or adjust permissions manually after creation if security is a concern.
deprecated The library is no longer actively maintained. Consider using tempfile.TemporaryDirectory from the standard library instead. ↓
fix Replace with: from tempfile import TemporaryDirectory
Imports
- TempDir
from tempdir import TempDir
Quickstart
import os
from tempdir import TempDir
with TempDir() as td:
td.write('test.txt', 'hello')
assert os.path.isdir(td.name)
assert not os.path.exists(td.name)