How to create Temporary files with tempfile module

PHOTO EMBED

Sat Jun 22 2024 18:32:43 GMT+0000 (Coordinated Universal Time)

Saved by @pynerds #python

import tempfile

temp = tempfile.TemporaryFile('w+')
print(temp)

#write to the file
temp.write("Hello world,")
temp.write("\nWelcome to Pynerds.")

#read from the file
temp.seek(0)
for i in temp.read():
    print(i, end = '')

temp.close()
content_copyCOPY

https://www.pynerds.com/tempfile-module-in-python/