Is there a better way to do this?

def QuietNamedTemporaryFile(**kwargs):

    '''
    Return a NamedTemporaryFile that doesn't complain when its file has already
    been unlinked at __del__ time.
    '''

    tf = tempfile.NamedTemporaryFile(**kwargs)

    def quiet_del():
        try:
            tf.close()
        except OSError:
            pass

    tf.__del__ = quiet_del

    return tf

Jason

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to