Understanding tempfile.TemporaryFile
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Thu Dec 27 22:36:19 EST 2007
On Thu, 27 Dec 2007 21:17:01 -0600, Shane Geiger wrote:
> import tempfile
> tmp = tempfile.mktemp()
>
> import os
> os.remove(tmp)
Not only does that not answer the Original Poster's question, but I don't
think it does what you seem to think it does.
>>> tmp = tempfile.mktemp()
>>> tmp
'/tmp/tmpZkS0Gj'
>>> type(tmp)
<type 'str'>
>>> import os
>>> os.remove(tmp)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 2] No such file or directory: '/tmp/tmpZkS0Gj'
You might like to read help(tempfile.mktemp).
(By the way... the whole point of using tempfile is to avoid needing to
delete the file by hand afterwards.)
--
Steven
More information about the Python-list
mailing list