Python Temporary Files and Directories

From NovaOrdis Knowledge Base
Revision as of 20:07, 13 June 2023 by Ovidiu (talk | contribs) (Created page with "=External= * https://docs.python.org/3/library/tempfile.html =Internal= * File Operations in Python Create a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

External

Internal



Create a named temporary file, write in it and return the name. The file is not automatically deleted after close(), the caller will need to delete it:

import tempfile
with tempfile.NamedTemporaryFile(mode='w+t', delete=False) as t:
  t.write(something)
  return t.name