import tempfile with tempfile.NamedTemporaryFile() as tmp: print("Temporary file created at", tmp.name) tmp.write(b"example content") tmp.seek(0) print("File content:", tmp.read())
import tempfile with tempfile.NamedTemporaryFile(suffix='.txt', prefix='example_', dir='/tmp') as tmp: print("Temporary file created at", tmp.name)This code creates a temporary file with a specific file name prefix ("example_") and file extension/suffix (".txt"), and specifies the directory where the file should be created ("/tmp"). The package library used is still `tempfile`.