On this page
  1. tempfile.mkstemp
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

tempfile.mkstemp

Prev: tempfile.mkdtemp | Up: tempfile | Next: tempfile.mktemp
Rel: tempfile.gettempdir, tempfile.gettempdirb, tempfile.gettempprefix, tempfile.gettempprefixb
Ref: docs.python.org — tempfile.mkstemp
Tags: #public #python3 #stdlib #tempfile


Import

import tempfile
from tempfile import mkstemp

Signature & Overview

tempfile.mkstemp(suffix=None, prefix=None, dir=None, text=False)

User-callable function to create and return a unique temporary file. The return value is a pair (fd, name) where fd is the file descriptor returned by os.open, and name is the filename.

Usage

import os
import tempfile

fd, path = tempfile.mkstemp(suffix=".tmp")
try:
    with os.fdopen(fd, "w", encoding="utf-8") as f:
        f.write("atomic data")
finally:
    os.unlink(path)

Gotchas

REPL Inspect

from tempfile import mkstemp
help(mkstemp)

Linked from

Related notes