Temporary file

aditya shukla adityashukla1983 at gmail.com
Thu Apr 9 20:03:25 EDT 2009


I am trying to create a temporary file.

import tempfile

temp = tempfile.NamedTemporaryFile(suffix='_suffix',
                                   prefix='prefix_',
                                   dir='/tmp',
                                   )
try:
    print 'temp:', temp
    print 'temp.name:', temp.name
finally:
    temp.close()


But when i do ls /tmp or ls -a /tmp i cannot find the file or if i try
to os.remove(temp.name)  it shows a message that the file is not
found.But print temp and print temp.name show
temp: <open file '<fdopen>', mode 'w+b' at 0xb7e84800>
temp.name: /home/swamp2/cacsgrad/axs9347/Desktop/prefix_zOfoX__suffix



Please help me to fix it.



Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090409/ffe438b3/attachment.html>


More information about the Python-list mailing list