Understanding tempfile.TemporaryFile

Shane Geiger sgeiger at ncee.net
Thu Dec 27 23:50:13 EST 2007


Yes, I knew this.  Good call, it was just a bad copy and paste example
of lines that showed up close together in a file.  My apologies.

>> 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.)
>
>
>
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy




More information about the Python-list mailing list