On this page
tempfile.gettempdir
Up: tempfile | Next: tempfile.gettempdirb
Rel: tempfile.gettempdirb, tempfile.gettempprefix, tempfile.gettempprefixb, tempfile.mkdtemp
Ref: docs.python.org — tempfile.gettempdir
Tags: #public #python3 #stdlib #tempfile
Import
import tempfile
from tempfile import gettempdir
Signature & Overview
tempfile.gettempdir()
Returns tempfile.tempdir as str.
Usage
from pathlib import Path
import tempfile
tmp_root = Path(tempfile.gettempdir())
assert tmp_root.is_dir()
Gotchas
- Respects
TMPDIR,TEMP,TMPenv vars: Don't hardcode/tmp—gettempdir()works across macOS, Linux, and Windows. - Cached after first call: Changing
os.environ["TMPDIR"]later won't updategettempdir()unlesstempfile.tempdir = Noneis reset.
REPL Inspect
from tempfile import gettempdir
help(gettempdir)
Linked from
- tuts/python3/stdlib_module/tempfile
- tuts/python3/stdlib_module/tempfile/gettempdirb
- tuts/python3/stdlib_module/tempfile/gettempprefix
- tuts/python3/stdlib_module/tempfile/gettempprefixb
- tuts/python3/stdlib_module/tempfile/mkdtemp
- tuts/python3/stdlib_module/tempfile/mkstemp
- tuts/python3/stdlib_module/tempfile/mktemp
- tuts/python3/stdlib_module/tempfile/NamedTemporaryFile
- tuts/python3/stdlib_module/tempfile/SpooledTemporaryFile
- tuts/python3/stdlib_module/tempfile/TemporaryDirectory
- tuts/python3/stdlib_module/tempfile/TemporaryFile
Related notes
- tuts/python3/stdlib_module/tempfile/gettempdirb Linked here; links to this page; shared tags: #stdlib, #tempfile
- tuts/python3/stdlib_module/tempfile/gettempprefix Linked here; links to this page; shared tags: #stdlib, #tempfile
- tuts/python3/stdlib_module/tempfile/gettempprefixb Linked here; links to this page; shared tags: #stdlib, #tempfile
- tuts/python3/stdlib_module/tempfile/mkdtemp Linked here; links to this page; shared tags: #stdlib, #tempfile
- tuts/python3/stdlib_module/tempfile Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/tempfile/mkstemp links to this page; shared tags: #stdlib, #tempfile
- tuts/python3/stdlib_module/tempfile/mktemp links to this page; shared tags: #stdlib, #tempfile
- tuts/python3/stdlib_module/tempfile/NamedTemporaryFile links to this page; shared tags: #stdlib, #tempfile
- tuts/python3/stdlib_module/tempfile/SpooledTemporaryFile links to this page; shared tags: #stdlib, #tempfile
- tuts/python3/stdlib_module/tempfile/TemporaryDirectory links to this page; shared tags: #stdlib, #tempfile