Python Glossary Русский

all Python 3tempfilefunction

tempfile.gettempdir()

directories and paths

Returns the directory where tempfile creates temporary files by default, such as /tmp.

Syntax

tempfile.gettempdir() -> str

The directory is chosen once and cached: first the TMPDIR, TEMP and TMP variables, then platform locations, then the current directory. So changing os.environ['TMPDIR'] after the first call has no effect. Never hard-code '/tmp': Windows and macOS use entirely different paths.

Examples

import os, tempfile
d = tempfile.gettempdir()
print(d)  # → ? /tmp на Linux
print(os.path.isabs(d))  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy