Python Glossary Русский

all Python 3deprecated in 3.0tempfilefunction

tempfile.mktemp()

temporary files

Deprecated: returns the name of a file that did not exist, without creating it; unsafe, use mkstemp() instead.

Syntax

tempfile.mktemp(suffix='', prefix='tmp', dir=None) -> str

It has been deprecated since Python 2.3 yet never removed and emits no warning, which is why it still shows up in old code. Between getting the name and creating the file another process may create a file with the same name (a race and a security hole). Use mkstemp() or NamedTemporaryFile(delete=False), which create the file immediately.

Examples

import os, tempfile
name = tempfile.mktemp(suffix='.txt')
print(os.path.exists(name))  # → False — файла нет, только имя

See also

Open in the full glossarydocs.python.orgReport an inaccuracy