On Sun, Mar 18, 2007 at 11:49:55AM +1200, Greg Ewing wrote:
> I've just discovered the hard way that NamedTemporaryFile
> automatically deletes the file when you close it. That
> doesn't seem very useful to me, since surely the reason
> you're using NamedTemporaryFile instead of TemporaryFile
> is that you want to do something else with it afterwards?
> What's the rationale for this behaviour?

For both TemporaryFile and NamedTemporaryFile, the rationale is that
"temporary" extends until the object is garbage collected.
TemporaryFile is deleted immediately (to prevent other applications from
modifying your temporary file).  NamedTemporaryFile is inteded for use
when you need access to the file by filename during the lifetime of the
file.  In either case, when the object goes, the file should too.

Dustin
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to