This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author djmdjm
Recipients
Date 2006-08-10.06:57:31
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Hi,

tempfile.NamedTemporaryFile provides a good interface
to creating temporary files, but its insistence on
deleting the file upon close is limiting. The attached
patch adds an optional parameter to NamedTemporaryFile
that allows persistence of the temp file after it has
been closed.

One use-case that demonstrates where keeping the
temporary file around is handy would be when you need
to safely create and fill a temp file before it is
atomically moved into place with os.rename(). E.g.

def update_conf(conf_path):
    old = open(conf_path)
    tmp = tempfile.NamedTemporaryFile(prefix =
os.basename(conf_path), \
        dir = os.dirname(conf_path), delete = False)
    for l in old:
        tmp.write(l.replace('war', 'peace'))
    close(old)
    close(tmp)
    os.link(conf_path, conf_path + ".old")
    os.rename(tmp.name, conf_path)
History
Date User Action Args
2007-08-23 15:54:01adminlinkissue1537850 messages
2007-08-23 15:54:01admincreate