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

tempfile.TemporaryFile

Prev: tempfile.TemporaryDirectory | Up: tempfile
Rel: tempfile.gettempdir, tempfile.gettempdirb, tempfile.gettempprefix, tempfile.gettempprefixb
Ref: docs.python.org — tempfile.TemporaryFile
Tags: #public #python3 #stdlib #tempfile


Import

import tempfile
from tempfile import TemporaryFile

Signature & Overview

tempfile.TemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, *, errors=None)

Create and return a temporary file.

Usage

import tempfile

with tempfile.TemporaryFile("w+b") as f:
    f.write(b"scratch bytes")
    f.seek(0)
    assert f.read() == b"scratch bytes"

Gotchas

REPL Inspect

from tempfile import TemporaryFile
help(TemporaryFile)

Linked from

Related notes