ID EN
Tempfile

mktemp

Python 3.11

Return an absolute pathname of a file that did not exist at the time the call is made. The prefix, suffix, and dir arguments are similar to those of mkstemp(), except that bytes file names, suffix=None and prefix=None are not supported.

Syntax

PYTHON
tempfile.mktemp(suffix='', prefix='tmp', dir=None)

Examples

Example 1
PYTHON
>>> f = NamedTemporaryFile(delete=False)
>>> f.name
'/tmp/tmptjujjt'
>>> f.write(b"Hello World!\n")
13
>>> f.close()
>>> os.unlink(f.name)
>>> os.path.exists(f.name)
False

See Also

mkstemp() mkstemp() mktemp() NamedTemporaryFile()