#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2008 Doug Hellmann All rights reserved. # """ """ __version__ = "$Id$" #end_pymotw_header import os import tempfile print 'Building a file name yourself:' filename = '/tmp/guess_my_name.%s.txt' % os.getpid() temp = open(filename, 'w+b') try: print 'temp:', temp print 'temp.name:', temp.name finally: temp.close() # Clean up the temporary file yourself os.remove(filename) print print 'TemporaryFile:' temp = tempfile.TemporaryFile() try: print 'temp:', temp print 'temp.name:', temp.name finally: # Automatically cleans up the file temp.close()