Category: tempfile

Problem

Create auto-cleaned temp files.

Solution

  with tempfile.NamedTemporaryFile(mode="w", delete=True) as f:
    f.write("data")
  

Notes

  • Adapt variable names and paths to your project
  • Add error handling for production use
  • See related chapters in the Learning Path