if prefix is None:
    prefix = '%s_%d_' % (os.path.basename(sys.argv[0]), os.getpid())
fileHandle, path = tempfile.mkstemp(prefix=prefix, suffix=suffix, dir=dir,
    text=text)
os.close(fileHandle)

def removeFile(path):
    os.remove(path)
logging.debug('temporaryFilename: rm -f %s' % path)
if removeOnExit:
    atexit.register(removeFile, path)
return path
How do I create a named temporary file on windows in Python?