Home >
Magazine >
#73 May 2000 >
Python Programming for Beginners >
Listing 8. Creating Temporary Files
Wednesday, March 29, 2000 | Last Updated 03:42:53 PM
Listing 8. Creating Temporary Files
#! /usr/local/bin/python
import os
import tempfile
import sys
try:
t_path = tempfile.mktemp()
ttt = os.open(t_path, os.O_CREAT | os.O_RDWR)
# O_RDWR allows read & write
except IOError:
print 'Error: Couldn\'t create temp file.'
sys.exit(0)
# always close and remove the temp file
# before you exit from script
os.close(ttt)
os.remove(t_path)