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
Date 2006-08-10.06:57:31
SpamBayes Score
Marked as misclassified

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(tmp), conf_path + ".old")
    os.rename(, conf_path)
Date User Action Args
2007-08-23 15:54:01adminlinkissue1537850 messages
2007-08-23 15:54:01admincreate