Creating a temporary file in Python

looping kadeko at gmail.com
Wed Oct 31 08:01:59 EDT 2007


Hi,

I want to create a temporary file, read it in an external command and
finally delete it (in Windows XP).

I try to use tempfile module but it doesn't work, the file couldn't be
open by my other process (error like: SP2-0310: unable to open file "c:
\docume~1\looping\locals~1\temp\tmpau81-s.sql")
Is there a way to make it work or I have to manually manage
everything ?

My non working code:

f = tempfile.NamedTemporaryFile(suffix='.sql')
f.write(txt)
f.flush()
p = subprocess.Popen([SQL_PLUS, '-s', dsn, '@', SQL_PLUS_SCRIPT,
f.name],
      stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.wait()
f.close()

Thanks for your help.




More information about the Python-list mailing list