permanent tempfile?

Colin Wildsmith cwildsmith at westnet.com.au
Mon Aug 21 03:08:45 EDT 2006


Hello,
I am trying to create a temp file, however the file that is created
is still there after the program has completed.
Why is this so?

CoLe

#!/usr/bin/python

import os, tempfile, sys

import tempfile

# creates a random file (text=True is textfile, text=False is binary
file)
ext = '.txt'
pfx = 'tmp'
dir = '/home/argon/PR0001/source/emc2/bin'
filename = tempfile.mkstemp(suffix=ext, prefix=pfx, dir=dir,
text=True)[1]
print filename  # eg. C:\Temp\tmpsnrfgk.txt

# test it ...
fout = open(filename, 'w')
fout.write("just a text file")
fout.close()
os.remove(filename)





More information about the Python-list mailing list