#! /usr/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)

# Note that you need to use both the os.O_CREAT and os.RDWR flags
# to tell the os.open function to create a temporary file for both reading and writing.
# Also, remember to close and remove all temporary files created before exiting a script.
# You will find more information on the functions, constants and variables
# used in the os, posix and tempfile sections of the Python Library Reference Manual.
