Patches item #1537850, was opened at 2006-08-10 16:57
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1537850&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Modules
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: djmdjm (djmdjm)
Assigned to: Nobody/Anonymous (nobody)
Summary: option to leave tempfile.NamedTemporaryFile around on close

Initial Comment:
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)


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1537850&group_id=5470
_______________________________________________
Patches mailing list
Patches@python.org
http://mail.python.org/mailman/listinfo/patches

Reply via email to